Segault on Python i2c call
-
Hello,
I'm rewriting some code that reads an I2C current sensor. In my rewrite I run into a segfault on an i2c write. The code in question is:
def pecmac(): """ Support for the Control Everything current sensor. Code has been tested with the 70A/3 channel model :return: """ logging.debug('...... i2c create') i2c = onionI2C.OnionI2C(0x01) #set the verbosity logging.debug('...... i2c set verbosity') i2c.setVerbosity(0x01) command2 = [ 0x6A, 0x02, 0x00, 0x00, 0x00, 0x00, 0xFE, ] logging.debug('...... i2c command2') i2c.writeBytes(0x2A, 0x92, command2)
The first time I run this code, all is well. But on the second run (after a 60s sleep inside the loop) I end up with a segfault.
The output I get (with the actual data collection output as well is:
20180203 21:31:41 Detected our hostname as [OMEGA-F6BB] 20180203 21:31:41 Creating database connection 20180203 21:31:41 .. Done 20180203 21:31:41 Reading sensor data 20180203 21:31:41 .. Reading data from sensor PECMAC 20180203 21:31:41 ...... i2c create 20180203 21:31:41 ...... i2c command2 20180203 21:31:42 ...... i2c readbytes 20180203 21:31:42 Type of Sensor: 4 | Maximum Current : 70A | No. of Channels: 3 20180203 21:31:42 Channel no: 1 | Current Value: 0.376A 20180203 21:31:42 Channel no: 2 | Current Value: 0.000A 20180203 21:31:42 Channel no: 3 | Current Value: 0.000A [{'Timestamp': 1517722302698L, 'Sensor': 'pecmac', 'Value': 0.376, 'Measurement': 'ch1_current'}, {'Timestamp': 1517722302698L, 'Sensor': 'pecmac', 'Value': 0.0, 'Measurement': 'ch2_current'}, {'Timestamp': 1517722302698L, 'Sensor': 'pecmac', 'Value': 0.0, 'Measurement': 'ch3_current'}] 20180203 21:31:42 Processing the sensor data 20180203 21:31:42 .. Sending data to UBIDOTS 20180203 21:31:42 .... Checking if Ubidots is Online 20180203 21:31:43 .. Submitting data to Ubidots 20180203 21:31:43 {"ch1_current": {"timestamp": 1517722302698, "value": 0.376}} 20180203 21:31:44 {"ch2_current": {"timestamp": 1517722302698, "value": 0.0}} 20180203 21:31:44 {"ch3_current": {"timestamp": 1517722302698, "value": 0.0}} 20180203 21:32:44 .. Reading data from sensor PECMAC 20180203 21:32:44 ...... i2c create 20180203 21:32:44 ...... i2c command2 Segmentation fault
Logread shows:
Sat Feb 3 21:32:44 2018 kern.info kernel: [ 1251.955047] do_page_fault(): sending SIGSEGV to python for invalid write access to 00000000 Sat Feb 3 21:32:44 2018 kern.info kernel: [ 1251.963673] epc = 77ce6864 in libc.so[77cbe000+92000] Sat Feb 3 21:32:44 2018 kern.info kernel: [ 1251.968855] ra = 779eac69 in libonioni2c.so[779ea000+11000]
Please note this is with some extra kernel modules to deal with I2C issues as per https://community.onion.io/topic/2312/i2c-detect-slave-method
tx
Bas