No connection on bootup

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()

Figures, as soon as I write up the problem a possible cause hits me… I’m booting up and running the script before the modem had time to come online. I’ve put a delay in there as so far it’s working fine.
Sorry for the distraction.

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