I cannot get a connection on boot up.
I’m running a Raspberry Pi 4, with the latest RPi OS (May2020). When I run the code from the command line I get a connection every time. When I run the code via crontab (@reboot) I get a connection error.
This happens whether I reboot via “reboot” command, or power down/up.
Here’s the code I’ve been running to test:
#!usr/bin/python3
import sys
import os
import datetime
import random
import threading
import json
import time
import shutil
from Hologram.HologramCloud import HologramCloud
from Hologram.CustomCloud import CustomCloud
from urllib.request import urlopen
from datetime import datetime
myAPI = 'XXXXXXXXXXXXXX'
#Configure Modem
credentials = {'devicekey': 'XXXXXXX'}
hologram = HologramCloud(credentials, network='cellular')
result = hologram.network.connect(timeout=10)
if result == False:
print('Failed to connect to cell network')
errlog=open("/home/pi/Prime/ErrLog.txt","a+")
errlog.write('Failed to connect to cell network: ' + time.strftime("%c") +'\n')
errlog.close()
else:
print('Connected to Cell Network')
errlog=open("/home/pi/Prime/ErrLog.txt","a+")
errlog.write('Connected to cell network: ' + time.strftime("%c") +'\n')
errlog.close()
hologram.network.disconnect()
sys.exit()