Very new here. Could use help with my 1st project.
I have a Verizon mifi mobile hotspot, its way off-grid and provides internet access for my IP cameras. If the hotspot gets an auto update, overheats or has a power surge it shuts off. Cant remotely do anything.
SO…I built a circuit for push-pull solenoid controller with relay. I wrote my first successful code to have the solenoid “push” a physical “power-on” button on my mobile hotspot. Tested! Works perfect!
However, Its important the solenoid code will run automatically when the Raspberry pi 3B loses network connectivity. Thus rebooting the hotspot.
Does anyone know how to write the code to have the Raspberry pi monitor the wifi and run the code that activates the solenoid?
Most solutions I looked at say to ping a known IP address and if it does not respond do something. ( ie activate the solenoid) The IP address could be the Verizon Mobile Hotspot.
The time between checking would depend on long you can tolerate the system being down and how often you want to retry.
Every 30 minutes, 30 seconds, 100 milliseconds, what ever works. Too often and the hotspot might not perform its main function correctly.
You say ‘way off-grid’ so I assume you could not ping Google or other ‘always on’ web sites.
The code for ping checking is below. This would run in a terminal window on the Pi 3B. You would start in manually or could start when the Pi boots by calling it in ‘rc.local’. The code runs all the time.
Using crontab might be better. Code has not been tested.
Regards
Jim
#!/bin/sh
while true; do
if ping -c5 xxx.xxx.xxx.xxx; then # IP address of Mobile Hotspot, eg 192.168.0.1
sleep 15m # 15 minutes, wait before testing wifi again
else
# add code to activate solenoid
sleep 5m # 5 minute, wait before trying again, so solenoid has chance to activate and wifi to start
fi
done
Thank you Jim and James.
I’m truly surprised and grateful for how much effort and quick response you guys have put in to my struggle.
I may be in over my head with python… writing code, punctuation, format all to make my solenoid script run.
I will definitely post my results!
And you can get our latest projects and tips straight away by following us on: