Hello Christoph Am Samstag, den 24.09.2016, 17:46 +0200 schrieb Christoph M. Becker: > On 24.09.2016 at 16:29, Torsten Rosenberger wrote: > > > i try to write a php extension for raspberry to get i2c data. > > This is my first extension. And maybe not the corect mailing list. > > > > The Problem, on the CLI I get the correct return value. > > If i run the same code in an webbrowser i got a wrong value. > > > > PHP_FUNCTION(i2c_read_value) > > { > > int arg_len; > > unsigned char reg; > > unsigned short res; > > > > if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", ®, > > &arg_len) == FAILURE){ > > That looks wrong. `reg` should be declared as `char *`. i have seen “s”: string, expects char* and int. but reg should be int it is a hex number for the i2c bus. > > > RETURN_FALSE; > > } > > > > res = i2c_smbus_read_byte_data(dev_fd, reg); > > Where is dev_fd defined and initialized? at the top of the extension script int dev_fd; > > > RETURN_LONG(res); > > } > > > > > > if i run these code in CLI > > <?php > > > > i2c_init(1,0x48,0); > > echo i2c_read_value(0x40); > > i2c_close(); > > > > ?> > > > > php i2c.php > > > > i get 49 these comes from an ADC and the range is 0 - 255. In an C > > programm i get the same value. > > > > wenn I run the script in an browser i get: 65535 > > > > someone can give me a hint ? > > There might be a permission or working directory issue. you are right! apache2 was not able to access /dev/i2c-1 so I add the apache2 user to the i2c group but also had to change the acces mod to the file. now it works Thanks's a lot! BR/Torsten -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php