I have a python script running on startup on a number of Raspberry Pis (model 3). The script watches a serial port for data from an air quality monitor then posts this data to a web server using the requests library. To allow the monitors to access the internet remotely, they are equipped with Huawei E5330 MiFis which the Pis access over wifi.

Intermittently, after starting up the script will fail to post data to the server. Other post requests from other sources will work and it will be possible to browse the web. This issue will usually persist until the Pi reboots, at which time it seems to be random whether it will work or won't. If the Pi is connected to another network (home or office wifi, for instance) it will always work fine - it only has a problem when connected to the Huawei MiFi.

The script itself is around 600 lines long, but the relevant line is:

result = eventlet.timeout.with_timeout(10, requests.post, target_url, json=data_dict, timeout=5, verify=False, timeout_value=None)

The eventlet library is used to prevent hanging requests (which were a problem before this fix was introduced). The intermittent problem connecting predates the use of eventlet. data_dict is correctly formatted json in each case.

I don't think the issue is a power drain causing voltage fluctuations, as it persists when the MiFi is running on battery power and not connected to the RPi. I've tried disabling all network interfaces other than wlan0 to no effect.

Has anyone encountered a similar problem, and do you have any suggested fixes?


The best fix I found for this was to add a "sleep 60" command to the start of the bash script starting the python programme. This lets the network come up before the python programme starts trying to use it. I'm afraid I don't understand why it works, but it seems to.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.