Error while trying to access modem

I am integrating the blues modem now into my bigger project.

It runs for a few minutes and then generates the following error:

Traceback (most recent call last):
  File "/home/pi/.local/lib/python3.7/site-packages/periphery/i2c.py", line 135, in transfer
fcntl.ioctl(self._fd, I2C._I2C_IOC_RDWR, i2c_xfer, False)
OSError: [Errno 121] Remote I/O error

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/pi/python/20210416/dispatcher3.py", line 468, in fifteen_sec_updates
rsp = card.Transaction(req)
  File "/home/pi/.local/lib/python3.7/site-packages/notecard/notecard.py", line 289, in Transaction
self.i2c.transfer(self.addr, msgs)
  File "/home/pi/.local/lib/python3.7/site-packages/periphery/i2c.py", line 137, in transfer
raise I2CError(e.errno, "I2C transfer: " + e.strerror)
periphery.i2c.I2CError: [Errno 121] I2C transfer: Remote I/O error

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/pi/python/20210416/dispatcher3.py", line 519, in <module>
fifteen_sec_updates()
  File "/home/pi/python/20210416/dispatcher3.py", line 474, in fifteen_sec_updates
print(rsp)
UnboundLocalError: local variable 'rsp' referenced before assignment

The error is triggered from:

try:

    req = {"req" :"note.add"}
    req["file"] = "vstdata.qo"
    req["sync"] = True
    req["body"] = to_modem
    
    rsp = card.Transaction(req)
    
except:    

    print('No response from modem.  Will keep trying...')

    print(rsp)

The modem is setup with this:

from periphery import I2C
import notecard

productUID = "com.xxxxx.yyyyyyy:zzzzzzz"

port = I2C("/dev/i2c-1")
card = notecard.OpenI2C(port,0,0)

req = {"req": "hub.set"}
req["product"] = productUID
req["mode"] = "continuous"
req["sync"] = True
req["outbound"] = 15

rsp = card.Transaction(req)

Which does work and gives me no errors. I had gone back and forth a couple of weeks ago with @RobLauer who was very helpful in getting the modem setup.

I think I am losing connection and then the internal note buffer is getting filled up. My questions are:

  1. how can I check for this?
  2. how can I possibly delete notes that are queued up (If this is the cause)?
  3. how can I check if the modem is not connected and possibly trap this error so that I can buffer the items and resend later when the modem is online?

Thanks,

Todd

Do you know (approximately) the size of the notes being generated?

You can always delete note files with the file.delete API.

What I am sending to the modem looks like:

{“c”:10013,“f”:145,“id”:“CP2X-TEST”,“m”:0,“p”:-0.07}

i’m sending this every 15 seconds. I assume the modem is going offline at somepoint and the notes are accumulating. What I would really like is to trap the going off line and then start buffering the data externally so that I can resend it later.

Hey @vstadmin, if you are sending Notes that frequently, I suggest using Templates to maximize the number of Notes that you can capture between syncs. Without using a template, the Notecard will reject Notes after it has 100 pending sync.

I will look through the Templates. Any idea on how to stop the program from crashing other than the try / except clauses I already have in place?

as a continuation, I think I am having some kind of I2C conflict.

The modem requires:

port = I2C("/dev/i2c-1")
card = notecard.OpenI2C(port,0,0)

and I am using the MCP23017 module with Adafruits drivers that use:

from adafruit_mcp230xx.mcp23017 import MCP23017
i2c = busio.I2C(board.SCL, board.SDA)

mcp = MCP23017(i2c)

I fear I have a conflict somewhere and I’m not good enough to discover where or how to correct it.
Any help would be greatly appreciated!

The default Notecard I2C address is 0x17 and you can change that with the card.io API.

It looks like the MCP23017 module uses other I2C addresses though, so I would guess that you don’t have a conflict.

Argh, I was wrong - you actually have two I2C objects using the same bus (port and i2c). You might be able to just pass the port object instead, like: mcp = MCP23017(port)

@RobLauer Thank you. I will try that.

Unfortunately,

mcp = MCP23017(i2c)

# Setup Pins for Relays

pin0 = mcp.get_pin(0)
pin1 = mcp.get_pin(1)
pin2 = mcp.get_pin(2)
pin3 = mcp.get_pin(3)
pin0.direction = Direction.OUTPUT
pin1.direction = Direction.OUTPUT
pin2.direction = Direction.OUTPUT
pin3.direction = Direction.OUTPUT

does not work. I get:

Traceback (most recent call last):
  File "dispatcher3.py", line 69, in <module>
    mcp = MCP23017(port)
  File "/usr/local/lib/python3.7/dist-packages/adafruit_mcp230xx/mcp23017.py", line 49, in __init__
    super().__init__(i2c, address)
  File "/usr/local/lib/python3.7/dist-packages/adafruit_mcp230xx/mcp230xx.py", line 31, in __init__
    self._device = i2c_device.I2CDevice(i2c, address)
  File "/usr/local/lib/python3.7/dist-packages/adafruit_bus_device/i2c_device.py", line 50, in __init__
    self.__probe_for_device()
  File "/usr/local/lib/python3.7/dist-packages/adafruit_bus_device/i2c_device.py", line 151, in __probe_for_device
    while not self.i2c.try_lock():
AttributeError: 'I2C' object has no attribute 'try_lock'

Just want to confirm you’re only using one object, as I see mcp = MCP23017(i2c) and mcp = MCP23017(port) above.

Yes,

Its actually:

port = I2C(“/dev/i2c-1”)
card = notecard.OpenI2C(port,0,0)

req = {"req": "hub.set"}
req["product"] = productUID
req["mode"] = "continuous"
req["sync"] = True
req["outbound"] = 15

rsp = card.Transaction(req)

### End of modem setup

mcp = MCP23017(port)

# Setup Pins for Relays

pin0 = mcp.get_pin(0)
pin1 = mcp.get_pin(1)
pin2 = mcp.get_pin(2)
pin3 = mcp.get_pin(3)
pin0.direction = Direction.OUTPUT
pin1.direction = Direction.OUTPUT
pin2.direction = Direction.OUTPUT
pin3.direction = Direction.OUTPUT

It didnt copy / paste correctly before.

Can you try using the busio library implementation for both instead?

If that doesn’t work, we may need your full source to reproduce locally.

I did try that already. It was missing an attribute called “transfer”.

Should I drop the file in here or send it to support? Its about 10K

also, don’t laugh when you read it. I swear Im trying.

You can send a DM to me here, thanks.

Any ideas with the i2C conflict yet?