OSError: [Errno 202] EAI_FAIL when connected to NB-IOT (Vodafone Germany)
I am developing on an gpy board the last few weeks and everything went good so far.
My application is running without any issues over a WIFI connection and now I started to figure out to obtain a connection via LTE-M (with NB-IOT) with a Vodafone simcard ordered via the Pycom online store (a prepaid card). After the modem firmware update to NB-IOT I tried to let the board connect to the cellular network which worked flawlessly. When I want to send data with sockets or usockets (in my later application is a mqtt client running), I allways get the following error:
OSError: [Errno 202] EAI_FAIL
It seams that other people in the forum have the same issue too and that there are often no real answers or constructive solutions to solve the problem. So what should I do?
This is the code to test the connection at the moment:
import socket import ssl import time from network import LTE import uselect as select lte = LTE() lte.disconnect() lte.reset() lte.attach(band=20, apn="pycom.io") while not lte.isattached(): print("Attaching...") time.sleep(0.25) lte.connect() # start a data session and obtain an IP address while not lte.isconnected(): print("Attached but not Connected...") time.sleep(0.25) print("Connected...") socket.dnsserver(0,'126.96.36.199') socket.dnsserver(1,'188.8.131.52') a = socket.getaddrinfo('www.google.com', 443)[-1] s= socket.socket() s.setblocking(False) s = ssl.wrap_socket(s) try: s.connect(a) except OSError as e: if str(e) == '119': # For non-Blocking sockets 119 is EINPROGRESS print("In Progress") else: raise e poller = select.poll() poller.register(s, select.POLLOUT | select.POLLIN) while True: res = poller.poll(1000) if res: if res & select.POLLOUT: print("Doing Handshake") s.do_handshake() print("Handshake Done") s.send(b"GET / HTTP/1.0\r\n\r\n") poller.modify(s,select.POLLIN) continue if res & select.POLLIN: print(s.recv(4092)) break break lte.disconnect() lte.dettach()
The output shows:
Attaching... Attaching... Attaching... Attaching... Connected... Traceback (most recent call last): File "main.py", line 24, in <module> OSError: [Errno 202] EAI_FAIL Pycom MicroPython 1.20.2.rc9 [v1.11-1a257d8] on 2020-06-10; GPy with ESP32 Pybytes Version: 1.5.0 Type "help()" for more information. >>>
I would appreciate any suggestions ...
@ahmadelmasri Do you know if the data consumed from the subscriber in the way you describe is encoded in a specialized binary format? I just tried to send a signal and using
mosquitto_subclient from Paho I am getting non-readable data.
I am calling mosquitto as follows:
mosquitto_sub -v -h mqtt.pybytes.pycom.io -u <user> -P <token> -t 'u<token>'
This post is deleted!
@ahmadelmasri Thank you - i will try that...
@MR-MediaVision Another option could be is subscribe to the MQTT server, so this may be faster in your case.
To get device messages:
- login using device token and username (your email)
- subscribe to topic (u+device token) example (u0....649-b116-4..3-acc3-21dd8....e52)
- server (mqtt.pybytes.pycom.io)
- Port 1883
@ahmadelmasri Hi Ahmad, I tried the thing with the webhook. First I send the data with the help of pybytes.send command to pybytes - it is working so far but not really realtime. Is there a way to let the new data apear imediately after sending with pybytes.send? At the moment it seams that there is a fixed interval after the new data apears in pybytes and ignite the webhook. For our application it is necessary to get the data fast after sending. We want to minitor a motorized door where the GYP board has to sense whether the door is moving / standing / is open or closed as a way to troubleshoot it. So it is importantent to get a direct feedback of the state. If the way with the pybytes.send and the webhook is so sluggish we can give up the idea to use it.
@ahmadelmasri I will have a try to deal with webhook function. I think for the beginning of our project it will be no huge compromise to route the data through pypytes. I hope that it will be easier to get in touch with open NB-IOT simcards in the future.
Unfortunately, yes you cannot connect to your server using the provided SIMs for now.
But using Pybtes you can create a
webhookand data will be transmitted to your server.
If I can be of assistance, please do not hesitate to contact me.
Ahmad El Masri
MR-MediaVision last edited by MR-MediaVision
@ahmadelmasri Good morning, ok may be there is something about the simcard I've read in the past butI don't understood it. At the end our goal has to be that we are able to speak to on of our VM servers which is running a mqtt broker. So you say we will be not able to acomplish that with the simcard we bought from your online shop because the connection is restricted to your server platform? Is there a way to get another simcard to access the "full" Internet over nb-iot?
Kindly note that this error is because you are trying to connect to
As listed on the webshop that Vodafone’s NB-IoT SIMs are only available using our Pycom devices and Pybytes management platform. You cannot currently use it with other cellular connectivity management platforms.
Another point is that the connection depends on the coverage of the area where the device is available.
N.B.: Pycom is not responsible for Vodafone’s network roll-out, and Pycom has no way to determine if a network is available for each customer.