GSM Shield with Raspberry Pi Port Open - raspberry-pi

I have connected a-gsm shield http://itbrainpower.net/a-gsm/downloadables/a-gsm-series-presentation-v1.01.pdf with Raspberry Pi 3.
I have imported and attempted to execute power on code http://itbrainpower.net/a-gsm/RaspberryPI-gsm-shield-library-powerOnOff-demo-code-a-gsm. However, I am getting the following error message:
sudo ./poweronoff.py
Traceback (most recent call last):
File "./poweronoff.py", line 66, in <module>
agsm.open()
File "/usr/lib/python2.7/dist-packages/serial/serialposix.py", line 271, in open
raise SerialException("Port is already open.")
serial.serialutil.SerialException: Port is already open.
I assume I need to open a different port. If that is the solution, how do I do it. If that is not the solution, what do I need to do to satisfy this error message?

Follow directions in this post https://www.raspberrypi.org/forums/viewtopic.php?uid=195125&f=28&t=165897&start=0.
Basically, "enable_uart=1" should be the last line in '/boot/config.txt' for serial port operations. Reboot the RPi3 and everything should work.

Related

Adafruit minimqtt on Pi Pico H with Wiznet RP2040 ethernet hat "RuntimeError: Failed to establish connection."

I'm trying to use the adafruit minimqtt library on a Pi Pico H, running circuitpython. I've been following this guide
I'm using a mosquito broker on my windows 10 laptop and connecting directly through an ethernet cable to the Wiznet hat, as in the tutorial. The code I'm using is copied directly from the example with the following changes:
changed the IP address on line 22 to that of my windows machine
uncommneted lines 68 and 70, and commented out line 73 to avoid using DHCP (someone else on the github has noted that the dhcp doesn't work). Also deleted the extra space in line 70
I get the following error:
Traceback (most recent call last):
File "<stdin>", line 84, in <module>
File "/lib/adafruit_minimqtt/adafruit_minimqtt.py", line 441, in connect
File "/lib/adafruit_minimqtt/adafruit_minimqtt.py", line 266, in _get_connect_socket
File "/lib/adafruit_wiznet5k/adafruit_wiznet5k_socket.py", line 246, in connect
File "/lib/adafruit_wiznet5k/adafruit_wiznet5k.py", line 570, in socket_connect
RuntimeError: Failed to establish connection.
I've looked through each of the scripts referenced and can't find any obvious errors (I'm not an expert in this so there might be something I've missed). I can't find anyone who's experienced this same error code, any help here would be appreciated.
I've tried running the first half of the code (up to line 68), and then pinging the pico from my laptop. I've also pinged my laptop from the board. Both were successful, so I don't think it's a hardware issue.
I've double checked that my broker is not in local mode. My .conf file contains
listener 1883
allow_anonymous true
and when I run mosquitto I get
C:\Users\me1xmtx\mosquitto>mosquitto -c rem.conf -v
1676306316: mosquitto version 2.0.15 starting
1676306316: Config loaded from rem.conf.
1676306316: Opening ipv6 listen socket on port 1883.
1676306316: Opening ipv4 listen socket on port 1883.
1676306316: mosquitto version 2.0.15 running
TCP (and UDP just in case) ports 1883 are open on the windows laptop

Cannot find SPI device

I am using Raspberry Pi Zero W with a PiTFT. I have managed to put an image on the screen as explained here: https://learn.adafruit.com/adafruit-pitft-28-inch-resistive-touchscreen-display-raspberry-pi
After that, I've tried to use the Adafruit Python ILI9341 as explained here: https://github.com/adafruit/Adafruit_Python_ILI9341
There is no problem at the instalation, BUT when I've tried to execute an example it said:
Traceback (most recent call last):
File "image.py", line 41, in <module>
disp = TFT.ILI9341(DC, rst=RST, spi=SPI.SpiDev(SPI_PORT,
SPI_DEVICE, max_speed_hz=64000000))
File "build/bdist.linux-armv6l/egg/Adafruit_GPIO/SPI.py", line 42,
in __init__
IOError: [Errno 2] No such file or directory
The tree hierarchy is missing starting with the 'egg' folder.
I've tried to manually create it, but I got the same error.
My instincts were that there is a problem with the SPI connection or the spidev kernel module.
There is no spi device in the /dev/ directory.
In the /boot/config.txt the spi is on, I've enabled it in the raspi-config menu. I've also checked and it is not even blacklisted.
I am using a pi image, not a PiTFT image.
Please HELP!

pyusb - [Error 5] on Linux, but not Windows

I'm trying to communicate with an AD9913 evaluation board (Analog Devices), which has a Cypress FX-2 USB controller. I wrote a fully functional Python library which works flawlessly on Windows 7 (using a driver generated through libusb-win32-1.2.6.0's inf-wizard.exe), but now I try to run the same software from a Raspberry Pi 3 with Raspbian Jessie and cannot seem to write or read.
The following minimal example works on Windows 7:
import os
os.environ['PYUSB_DEBUG'] = 'debug'
import usb.core
print "usb.core file:", usb.core.__file__
# get device
dev = usb.core.find(idVendor=0x0456, idProduct=0xEE25)
if dev is None:
raise ValueError("Device not found")
dev.set_configuration()
# get the firmware version
print "Write: ", dev.write(0x01, [0x00])
print "Read: ", dev.read(0x81, 7)
The ouput here is:
usb.core file: C:\Python27\lib\site-packages\usb\core.pyc
Write: 1
Read: array('B', [1, 0])
However, on the Raspberry several problems occur. First, the product ID is 0xEE24 (which I found out through dmesg), and second, the code example above gives
usb.core file: /usr/local/lib/python2.7/dist-packages/usb/core.pyc
Write:
Traceback (most recent call last):
File "usbtesting_minimal_linux.py", line 29, in <module>
print "Write: ", dev.write(0x01, [0x00])
File "/usr/local/lib/python2.7/dist-packages/usb/core.py", line 948, in write
self.__get_timeout(timeout)
File "/usr/local/lib/python2.7/dist-packages/usb/backend/libusb1.py", line 824, in bulk_write
timeout)
File "/usr/local/lib/python2.7/dist-packages/usb/backend/libusb1.py", line 920, in __write
_check(retval)
File "/usr/local/lib/python2.7/dist-packages/usb/backend/libusb1.py", line 595, in _check
raise USBError(_strerror(ret), ret, _libusb_errno[ret])
usb.core.USBError: [Errno 5] Input/Output Error
I'm executing the script by calling sudo python minimal_example.py, otherwise (as expected) I get usb.core.USBError: [Errno 13] Access denied (insufficient permissions). (For the testing described above, I removed the udev rules I added to allow access to my regular user account, and rebooted and replugged the device afterwards.)
I also noticed that on Windows, Configuration 1 (which is the only configuration) as revealed by adding
cfg = dev.get_active_configuration()
to aforementioned example script, has only one Interface 0, where as on Linux Interface 0 has no endpoints, but there are additional interfaces Interface 0, 1, Interface 0, 2 and Interface 0,3, the first of which is identical to the sole interface shown by Windows.
Detaching kernel drivers as described in this post -- which given my current understanding as a USB novice should not be necessary here -- does not resolve the problem.
I suspect that the issue stems from a difference between the Windows/libusb and Linux implementation/backend of the USB communication (already hinted at by the fact that the productID shown is different for the very same piece of hardware attached), which might require some changes to the way I'm writing to the USB endpoint.
I'm happy to provide more information if needed and welcome all hints and suggestions.
Most likely, this error caused by the firmware is not uploaded. Usually speaking, FX-2 USB controller does not save the firmware.
Although I still cannot communicate with the device on the Raspberry Pi, the Error 5 problem is resolved by explicitly selecting a suitable alternate setting with proper endpoints, e.g.
dev.set_interface_altsetting(interface = 0, alternate_setting = 1)
Then read/write requests no longer fail with Error 5, but with a timeout error (which is Error 110 for libusb1 and None for libusb0).
I now suspect that there is a problem with how the device is detected by the operating system, since not only the productID changes between Windows and Linux, but also wMaxPacketSize for the endpoints I'm interested in is given as 64 bytes on Windows and 512 bytes on Linux.
Once I'm further along in my troubleshooting, I will either open a new question and add the link as a comment to this answer (or post the whole solution here in case I can solve everything right away).

Jupyterhub on Google compute engine

I'm trying to set up a Jupyterhub instance to serve IPython notebooks on a Google Compute Engine. However, when running jupyterhub i am faced with an error regarding sockets:
[E 2015-08-31 10:27:55.617 JupyterHub app:1097]
Traceback (most recent call last):
File "/home/esten/anaconda3/envs/py3k/lib/python3.3/site- packages/jupyterhub/app.py", line 1095, in launch_instance_async
yield self.start()
File "/home/esten/anaconda3/envs/py3k/lib/python3.3/site-packages/jupyterhub/app.py", line 1027, in start
self.http_server.listen(self.hub_port, address=self.hub_ip)
File "/home/esten/anaconda3/envs/py3k/lib/python3.3/site-packages/tornado/tcpserver.py", line 126, in listen
sockets = bind_sockets(port, address=address)
File "/home/esten/anaconda3/envs/py3k/lib/python3.3/site-packages/tornado/netutil.py", line 187, in bind_sockets
sock.bind(sockaddr)
OSError: [Errno 99] Cannot assign requested address
The address/port assigned by the config file is localhost/8081, and binding a socket like below works perfectly fine
import socket
s = socket.socket()
s.bind(("localhost", 8081))
Does jupyterhub look somewhere else for the information or is something done differently when binding the socket through my own code?
This seems to be a problem with GCE not supporting ipv6.
I found this link explaining that enabling ipv6 solved the issue on another machine.
Running using --ip solved the issue:
jupyter notebook --ip="*"

Celery: Remote workers frequently losing connection

I have a Celery broker running on a cloud server (Django app), and two workers on local servers in my office connected behind a NAT. The local workers frequently lose connection, and have to be restarted to re-establish connection with the broker. Usually celeryd restart hangs the first time I try it, so I have to ctr+C and retry once or twice to get it back up and connected. The workers' logs two most common errors:
[2014-08-03 00:08:45,398: WARNING/MainProcess] consumer: Connection to broker lost. Trying to re-establish the connection...
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/celery/worker/consumer.py", line 278, in start
blueprint.start(self)
File "/usr/local/lib/python2.7/dist-packages/celery/bootsteps.py", line 123, in start
step.start(parent)
File "/usr/local/lib/python2.7/dist-packages/celery/worker/consumer.py", line 796, in start
c.loop(*c.loop_args())
File "/usr/local/lib/python2.7/dist-packages/celery/worker/loops.py", line 72, in asynloop
next(loop)
File "/usr/local/lib/python2.7/dist-packages/kombu/async/hub.py", line 320, in create_loop
cb(*cbargs)
File "/usr/local/lib/python2.7/dist-packages/kombu/transport/base.py", line 159, in on_readable
reader(loop)
File "/usr/local/lib/python2.7/dist-packages/kombu/transport/base.py", line 142, in _read
raise ConnectionError('Socket was disconnected')
ConnectionError: Socket was disconnected
[2014-03-07 20:15:41,963: CRITICAL/MainProcess] Couldn't ack 11, reason:RecoverableConnectionError(None, 'connection already closed', None, '')
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/kombu/message.py", line 93, in ack_log_error
self.ack()
File "/usr/local/lib/python2.7/dist-packages/kombu/message.py", line 88, in ack
self.channel.basic_ack(self.delivery_tag)
File "/usr/local/lib/python2.7/dist-packages/amqp/channel.py", line 1583, in basic_ack
self._send_method((60, 80), args)
File "/usr/local/lib/python2.7/dist-packages/amqp/abstract_channel.py", line 50, in _send_method
raise RecoverableConnectionError('connection already closed')
How do I go about debugging this? Is the fact that the workers are behind a NAT an issue? Is there a good tool to monitor whether the workers have lost connection? At least with that, I could get them back online by manually restarting the worker.
Unfortunately yes, there is a problem with late acks in Celery+Kombu - task handler tries to use closed connection.
I worked around it like this:
CELERY_CONFIG = {
'CELERYD_MAX_TASKS_PER_CHILD': 1,
'CELERYD_PREFETCH_MULTIPLIER': 1,
'CELERY_ACKS_LATE': True,
}
CELERYD_MAX_TASKS_PER_CHILD - guarantees that worker will be restarted after finishing the task.
As for the tasks that already lost connection, there is nothing you can do right now. Maybe it'll be fixed in version 4. I just make sure that the tasks are as idempotent as possible.