Tutorial: Changing MQTT Server IP on Solar SkyCam
The MQTT Server IP is set during initial configuration of the Solar SkyCam remote WeatherSense camera. The Solar
SkyCam is a solar powered remote camera supported by SkyWeather2 and the WeatherSense product line.
Solar SkyCam is a great addition to your SkyWeather2 weather system or to your WeatherSense sensors. It provides a solar powered camera and transmits the picture to the Raspberry Pi. The Raspberry Pi builds a daily TimeLapse video and stores the pictures on the Raspberry Pi.
What is the Problem?
If your MQTT Broker Server (usually your Raspberry Pi) changes IP addresses, either by your intent or by a reboot of your router. Some routers behave well after a reboot, assigning the same IPs to the devices using DCHP, but some (such as the Netgear Orbi) will shake up your network after a reboot and scramble your IPs. Note that the DCHP standard does not require the same IP address to be handed out each time, or even on each refresh, so it’s not incorrect, but the Netgear Orbi is one of the few WiFi routers that will scramble your IPs on every boot.
The only way to reset the MQTT address in the Solar SkyCam (for older versions of software before V24) was to turn off your router and reconfigure the SkyCam by connecting to the onboard Access Point as shown in the manual.
This works with most routers, but not with the Netgear Orbi because turning it off just scrambled the IP addresses again.
This lead to us building a new version of https://github.com/switchdoclabs/SDL_ESP32_WeatherSenseSkyCam.
Version 24 of the SkyCam software now contains a REST interface that can be used to reconfigure the SkyCam via some tricky python software.
First, let’s talk about what the WeatherSense family of sensors are.
What is WeatherSense?
WeatherSense is an open source protocol and software that allows weather and environmental instruments communicate with the Raspberry Pi, ESP32 and Arduino based computers. You have ALL the software source code available to learn how these devices work and to make your own modification. A great way to learn and develop your own abilities.
The WeatherSense Sensors
SwitchDoc Labs has developed a set of WeatherSense compatible sensors and has several others in development. The current list of supported sensors are:
- WeatherSense WeatherRack2
- WeatherSense Indoor T/H Sensors
- WeatherSense Solar Powered Air Quality (AQI) Sensor
- WeatherSense Solar Powered Lightning Detector
- WeatherSense Solar Powered AfterShock Earthquake Detector
- WeatherSense Solar Powered SkyCam
- WeatherSense RadSense Radiation Detector (Coming Soon)
- WeatherSense SolarMAX2 Solar Power System and Controller
For more detailed information on WeatherSense, check out this article.
Resetting the MQTT Address on your Solar SkyCams
The way we have fixed the changing MQTT problem was by adding a REST interface to the Solar SkyCam ESP32 software.
You can download Version 24 of the software here:
https://github.com/switchdoclabs/SDL_ESP32_WeatherSenseSkyCam
To compile this and download it to your SkyCam unit requires you to follow a tutorial to install the ESP32 libraries on the Arduino IDE and then select the “AI Thinker ESP32” as the board type.
Once you have installed V24 on your Solar SkyCam, then proceed to the next section.
What function does the REST Interface have?
Representational state transfer (REST) is a software architectural style that uses URLs to control devices through a web server like interface.
We have implemented a simple REST interface to accomplish this, the checkForID command. In URL form this is:
http://<ip of SkyCam>/checkForID?params=<ip of your Pi MQTT Broker>,<MQTT Port Number>
For example:
http://192.168.1.2/checkForID?params=192.168.1.36, 1883
The REST interface is active on your SkyCam in two modes.
Normal Mode: REST interface is only active for about 5 seconds when the SkyCam is taking a picture (usually every 60 seconds depending on your Sensor Cycle.
Lost Mode: If your SkyCam ESP32 can not talk to the MQTT broker (such as when your IP address changes), SkyCam will turn on the REST interface and stay active until you reset the MQTT broker address with the REST command above. This will dramatically reduce your battery life!
We still have one problem, what are the SkyCam IP addresses? They will change with a flaky router reboot too!
The Python Solution: fixSkyCamRemote.py
We have written a Python program, fixSkyCamRemote.py, that will scan your local network looking for SkyCam devices and when it finds them, will update the SkyCam with the IP of your Pi.
Two considerations:
- You must run the program on the same Pi that is running the MQTT broker. Or modify the code to set the SkyCam to an address of your choice
- The SkyCam device should be running a sensor cycle of 60 seconds (the default). If you are running a much longer sensor cycle, then you will need to modify the program to “catch” the SkyCam running. This is only applicable if you are changing the MQTT broker address from one working broker IP to another (Normal Mode) above.
You can find the fixSkyCamRemote.py program in the SDL_Pi_WeatherSense repository.
https://github.com/switchdoclabs/SDL_Pi_WeatherSense
This program will take a long time to run! About 300 minutes to compete a full scan.
Start the program by typing:
sudo python3 fixSkyCamRemote.py
This program will scan your network looking for SkyCams and reseting the MQTT broker addresses. Then your SkyCams will be back supplying all those good pictures to your Raspberry Pi.
The results will look something like this:
pi@SwitchDocLabs:~/SDL_Pi_WeatherSense $ sudo python3 fixSkyCamRemote.py
############################
Starting Find SkyCam Remote
############################
This will run for about 300 minutes
Starting Scan
Your Computer IP Address is:192.168.1.5
Your Computer CIDR is: 192.168.1.0/24
Start Time = 2022-04-10 12:43:05.572913
checking IP: 192.168.1.1
checking IP: 192.168.1.2
>>>>>>>>>>>>>>>>
SkyCam Remote Found. IP Address= 192.168.1.2
ID,version= 26FD,24
>>>>>>>>>>>>>>>>
checking IP: 192.168.1.3
checking IP: 192.168.1.4
>>>>>>>>>>>>>>>>
SkyCam Remote Found. IP Address= 192.168.1.4
ID,version= 9271,24
>>>>>>>>>>>>>>>>
checking IP: 192.168.1.5
checking IP: 192.168.1.6
.
.
.