pcfens / RaspberryPi-AS3935

A basic library for working with the AS3935 that's connected to the Raspberry Pi.
Other
52 stars 24 forks source link

IOError: [Errno 121] Remote I/O error when LAN cable unplugged #28

Open JsBergbau opened 5 years ago

JsBergbau commented 5 years ago

I have RPI 3. I run ./demo.py after I've set adress to 0x03 and Bus to 0x01 Everything is fine. As soon as I unplug LAN cable and connect via Wifi, I get

pi@raspberrypi:~/RaspberryPi-AS3935 $ ./demo.py Traceback (most recent call last): File "./demo.py", line 15, in sensor.set_indoors(True) File "/home/pi/RaspberryPi-AS3935/RPi_AS3935/RPi_AS3935.py", line 162, in set_indoors self.read_data() File "/home/pi/RaspberryPi-AS3935/RPi_AS3935/RPi_AS3935.py", line 234, in read_data self.registers = self.i2cbus.read_i2c_block_data(self.address, 0x00) IOError: [Errno 121] Remote I/O error

Beeing connected via Wifi and LAN and then pulling the cable also leads to an error.

pcfens commented 5 years ago

Are you disconnecting the cable while demo.py is running or disconnecting then running it again? I'm a little confused about why the set_indoors method is in the trace output if the script was already running and in steady state.

JsBergbau commented 5 years ago

That makes no difference. When disconnecting while running, script aborts, when disconnected and trying to start, script won't start.

When started, connected via Wifi-Interface and then pulling LAN cable, following output is written

/RaspberryPi-AS3935 $ ./demo.py
Waiting for lightning - or at least something that looks like it
Noise level too high - adjusting
Noise level too high - adjusting
Traceback (most recent call last):
  File "./demo.py", line 26, in handle_interrupt
    sensor.raise_noise_floor()
  File "/home/pi/RaspberryPi-AS3935/RPi_AS3935/RPi_AS3935.py", line 104, in raise_noise_floor
    floor = self.get_noise_floor()
  File "/home/pi/RaspberryPi-AS3935/RPi_AS3935/RPi_AS3935.py", line 72, in get_noise_floor
    self.read_data()
  File "/home/pi/RaspberryPi-AS3935/RPi_AS3935/RPi_AS3935.py", line 234, in read_data
    self.registers = self.i2cbus.read_i2c_block_data(self.address, 0x00)
IOError: [Errno 121] Remote I/O error
Traceback (most recent call last):
  File "./demo.py", line 23, in handle_interrupt
    reason = sensor.get_interrupt()
  File "/home/pi/RaspberryPi-AS3935/RPi_AS3935/RPi_AS3935.py", line 48, in get_interrupt
    self.read_data()
  File "/home/pi/RaspberryPi-AS3935/RPi_AS3935/RPi_AS3935.py", line 234, in read_data
    self.registers = self.i2cbus.read_i2c_block_data(self.address, 0x00)
IOError: [Errno 121] Remote I/O error
Noise level too high - adjusting
^CTraceback (most recent call last):
  File "./demo.py", line 45, in <module>
    time.sleep(1.0)
KeyboardInterrupt

As you see I then close the progam via STRG+C

when only connected via Wifi, following output

 ./demo.py
Traceback (most recent call last):
  File "./demo.py", line 16, in <module>
    sensor.set_noise_floor(0)
  File "/home/pi/RaspberryPi-AS3935/RPi_AS3935/RPi_AS3935.py", line 81, in set_noise_floor
    self.read_data()
  File "/home/pi/RaspberryPi-AS3935/RPi_AS3935/RPi_AS3935.py", line 234, in read_data
    self.registers = self.i2cbus.read_i2c_block_data(self.address, 0x00)
IOError: [Errno 121] Remote I/O error

So script doesn't even start.

EDIT: When bringing eth0 down while plugged script works fine. Strange.

Edit2: Its also no mechanical issue. I can move the sensor quite fast and no errors are shown.

pcfens commented 5 years ago

It's almost like the disconnect of the cable is creating enough noise to trigger an interrupt, then you run in to some other bug (likely in smbus or the hardware implementation). Does wifi only work if the Pi boots without ever being physically connected?

Do you have any other I2C devices you can try out on a read loop? The I/O error feels a lot like something changes on the Pi when the network state changes.

thymjan commented 5 years ago

I've also got IOErrors when using the library (with a raspbian stretch on a raspberry pi 3 A+).

I've changed the main loop to the following:

while True:
    try:
        time.sleep(1.0)

    except Exception as ex:
        print "Error: %s" % (ex-message)
        GPIO.cleanup()

The script is now running for several days. Maybe this helps?

JsBergbau commented 5 years ago

Does wifi only work if the Pi boots without ever being physically connected?

Sadly no.

Do you have any other I2C devices you can try out on a read loop?

I could connect a BME280. A BME280 works on a Pi Zero W flawlessly

JsBergbau commented 5 years ago

Very strange. When I plug 4 AA recharchable batteries as UPS this error shows up when trying to ``` start demo.py

Traceback (most recent call last):
  File "./demo.py", line 15, in <module>
    sensor.set_indoors(True)
  File "/home/pi/RaspberryPi-AS3935/RPi_AS3935/RPi_AS3935.py", line 167, in set_indoors
    self.set_byte(0x00, write_value)
  File "/home/pi/RaspberryPi-AS3935/RPi_AS3935/RPi_AS3935.py", line 222, in set_byte
    self.i2cbus.write_byte_data(self.address, register, value)
IOError: [Errno 121] Remote I/O error

When started and then plugged program continues working (watched only a few seconds). Then killing and restarting won't work.