Automatic reconnection after reboot


I am running the following code that send temperature and humidity data to the cloud which works perfectly at sending data to the Hologram Console but when the raspberry pi is rebooted, or the power is disconnected it stops sending data. I’d like to have a file that runs automatically upon power up or reboot.
I created a line of code in the rc.local file with path name (python /home/pi/ &) but upon reboot it only sends 1 data set (temp + humidity) and then no more data is sent.
It there a more successful way to ensure restart after a power failure or reboot?
I’m using a Nova LTE connected to a raspberry pi

import RPi.GPIO as GPIO ## Import GPIO library
import Adafruit_DHT ## Import temp/hum library
from Hologram.HologramCloud import HologramCloud ## Import Hologram cloud library
from time import sleep

GPIO.setmode(GPIO.BCM) ## Use broadcom pin numbering
#hologram = HologramCloud(“xxxxx”, network=‘cellular’, enable_inbound=False) ## Saved this just in case using Device Key is useful
hologram = HologramCloud(dict(), network=‘cellular’) ## connect from the cellular netowork

DHT_PIN = 21 ## GPIO pin the DHT sensor is attached to

def getTemp(DHT_PIN):
temperature = Adafruit_DHT.read_retry(DHT_SENSOR, DHT_PIN)[1]
temperature = temperature * 9/5.0 + 32 ## Convert temp to Fahrenheit

if temperature is not None:
    return str(temperature) + "F "
    return 'Sensor Error' 

def getHum(DHT_PIN):
humidity = Adafruit_DHT.read_retry(DHT_SENSOR, DHT_PIN)[0]

if humidity is not None:
    return str(humidity) + "H "
    return 'Sensor Error'

def toggleAlert():
if ALERT_ACTIVE == False:

def sendMessage(message, topic):
sent = hologram.sendMessage(message, topics=topic)

if sent == 0:
	print 'Success! Message sent to the cloud.'
	print message
	print 'Error type [' + sent + ']'
	print 'Error descriptions:'

while True:
hum = getHum(DHT_PIN)
temp = getTemp(DHT_PIN)

print("Console: Current Temperature is " + temp + "-Humidity is " + hum)
if ALERT_ACTIVE == True and temp > 71.0:
	message = "ALERT: Temperature is WICKED HOT! Current reading " + temp + hum + "!!"
	sendMessage(message, ["alert"])
	message = "Current Temperature is " + temp + "- Humidity is " + hum
	sendMessage(message, ["status"])

GPIO.cleanup() ## reset all pins ## Exercise 06 - disconnect from the cellular network


Hey @hickse,

These all looks correct to me. Are you getting any errors or warnings?


Follows is the error presented in the terminal (I’m using a different program that generates a JSON message) but the failure persists, with the following message:

Testing Hologram Cloud class…
Cloud type: HologramCloud
Traceback (most recent call last):
File “”, line 41, in
timeout = 3)
File “/usr/local/lib/python2.7/dist-packages/Hologram/”, line 112, in sendMessage
result = super(HologramCloud, self).sendMessage(output, timeout)
File “/usr/local/lib/python2.7/dist-packages/Hologram/”, line 78 , in sendMessage
resultbuf =
File “/usr/local/lib/python2.7/dist-packages/Hologram/Network/”, li ne 132, in send_message
return self.modem.send_message(data)
File “/usr/local/lib/python2.7/dist-packages/Hologram/Network/Modem/”, line 253, in send_message
raise SerialError(‘Timeout occurred waiting for message status’)
Exceptions.HologramError.SerialError: Timeout occurred waiting for message status

Sudo halogram disconnect does not allow for a successful reconnection. Only after a power down of the Nova and a restart does the program successfully continue for another period of time before it crashes. That makes me wonder if the connection to the cellular network may be the issue.


I run the script below on a Pi at boot and every 15 minutes using crontab. I’m sure this script could be improved with some more robust ping checking, retries, and a recheck of ping after re-connection. Can someone with mad Python skills help us out?

This works almost all the time, but occasionally the Nova R410 modem goes completely offline (even the blue light goes out) and I can’t recover without a reboot or remove/install the USB modem. Yes, I have a very beefy power supply on the Pi. I need an additional recovery step for a apparently lost USB modem. Anyone else seeing this?
if ping -q -c 1 -W 1 >/dev/null; then
echo “Ping Successful”
echo “Ping Failed”
sudo /usr/local/bin/hologram network disconnect
sleep 5
sudo /usr/local/bin/hologram modem reset
sleep 15
sudo /usr/local/bin/hologram network connect
echo “Connected”

closed #5

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.