wshealy
Full Member
 
Posts: 187
Raspberry Pi: Yes
|
Post by wshealy on Apr 1, 2022 16:09:46 GMT -8
I have been looking at the SkyCam code. I was thinking of putting it to sleep at dark and waking it up at sunrise. I can't seem to find any reference to clock time which surprised me since photos are time stamped.
The night load on my battery causes Sun to shutdown. Since it isn't good at night photography why shoot. Maybe if it can't do clock time I could somehow signal it to sleep and wake via wifi or 433.
Any thoughts?
Wallace
|
|
|
Post by SDL on Apr 2, 2022 10:18:36 GMT -8
Wallace, You could modify the software on the SkyCam to do that. Aside from that look at all the commands that you can send from python to the SkyCam. Look at the bottom of the SkyCam product page: shop.switchdoc.com/products/solar-skycam-weathersenseYou can modify MQTTCYCLECHANGE - Change the delay between pictures in seconds - defaults to 50 seconds To be set so it won't take pictures at night, then at sunrise you change it back to 50 seconds. Look at this software to see how to send the commands: testSkyCamRemote.py BP
|
|
|
Post by Jason on Apr 2, 2022 12:35:04 GMT -8
If you have the WeatherRack2, you could use NodeRED to use the sunlight value to set the cycle mentioned above.
Thanks,
Jason
|
|
n7qnm
Junior Member

Posts: 80
|
Post by n7qnm on Apr 18, 2022 10:12:30 GMT -8
I took a look at this over the weekend - some things I observed 1) As far as I can tell, the ESP32Cam itself does NOT know what time it is, so no way to do something simple like "don't take picture between these hours 2) As far as I can tell, there's no light sensor on the ESP32Cam, so no way to say "don't take pictures if it's not light" 3) MQTT cycle change will work, HOWEVER, since ESP32 is only "live" for a short time after it sends an INFO message and it only sends an INFO message after every "sleep interval", changing back to "day interval" is only possible during that "live" window.
What all of this implies is that the code that relies on "externally" changing the interval would have to look something like this: At Sunset get interval between sunset today and sunrise tomorrow set MQTTCYCLE to that interval At <some time before sunrise> begin wait for the INFO message at INFO message set MQTTCYCLE back to the "daylight" interval
Repeat Daily
I'm working on code to do this in my copious spare time :-)
Will post when I get something - and would definitely be open to other ideas
|
|
n7qnm
Junior Member

Posts: 80
|
Post by n7qnm on Apr 18, 2022 14:43:43 GMT -8
A friend suggested a "hardware solution" - a light sensor "switch" (SCR) connected to the 5V supply (which would be easy in series with the 5V switch. I found such a device designed to control 120V lights on eBay for $3.99 and ordered one. It comes out of China and so will be a few weeks getting here; but when it gets here I'll measure the current draw and see if it's worth a go. If not, I'm sure something could be made to work.
Results forthcoming
|
|
wshealy
Full Member
 
Posts: 187
Raspberry Pi: Yes
|
Post by wshealy on Apr 19, 2022 7:14:53 GMT -8
Great suggestion, keep me posted on China arrival. Is there a replacement version of ESP32CAM that would do better at night. Shame I can't get star photos, night weather, or even animal activity at night with this setup. I would like to have several. W
|
|
|
Post by SDL on Apr 19, 2022 9:33:32 GMT -8
n7qnm,
That's not a bad idea, BTW. I still think the software solution is better, but yours is very suitable.
BP
|
|
n7qnm
Junior Member

Posts: 80
|
Post by n7qnm on Apr 20, 2022 12:29:29 GMT -8
I'd prefer to do it in software as well; but, one of the issues I have with doing it the way I outlined was that if the INFO message (or the response) gets missed, you're stuck for another "cycle" before it gets changed. There are some interesting discussions about "wake on WAN" that I might chase.
Clay
|
|
|
Post by Jason on Apr 21, 2022 9:19:51 GMT -8
Most MQTT brokers support the option to RETAIN messages on the broker in order to prevent misses.
Thanks,
Jason
|
|
n7qnm
Junior Member

Posts: 80
|
Post by n7qnm on May 14, 2022 8:52:12 GMT -8
Some updates - my SkyCam with two solar panels has been mounted outside here in E Washington for about two weeks. Starting from a fully charged battery, this morning the voltage dropped to 3.43V, so it's off. Today is cloudy and rainy, so I don't expect I'll get any relief soon. Has anyone else solved this?
The sensor/switch arrived from China last week - it's really too large to put in the SkyCam box; but, that looks the most promising. My eventual plan is to have an entire sensor array on a pole in our field, with 8+ SkyCams, so I'll be powering the whole system from a SolarMax with a BIG battery and just running 12V everywhere, dropped to 5V at the sensors. I guess this just increases the priority of that project :-)
Clay
|
|
wshealy
Full Member
 
Posts: 187
Raspberry Pi: Yes
|
Post by wshealy on May 19, 2022 15:01:55 GMT -8
Great idea W
|
|
n7qnm
Junior Member

Posts: 80
|
Post by n7qnm on Oct 14, 2022 13:51:57 GMT -8
I finally managed to get what I think is a viable way to put remote SkyCams to sleep at night; to conserve power so I can get a picture every 15 minutes for my web page (www.n7qnm.net). I've got a combination of Linux shell scripts and python code.
Here's the high level - For sunset - I have a shell script that calls sunwait (https://github.com/risacher/sunwait) that I run at 1600 every day. sunwait has a "wait" function that blocks until sunset and then returns. The second line in the shell script uploads the current picture to my website (a sunset picture) The third line invokes a python script that uses Astral to calculate the number of seconds until tomorrow's sunrise and sends that to the camera.
For sunrise - I have a python script that connects to the MQTT broker and waits for the "INFO" message from the camera, when it finds that, it sends a command to the camera and resets the cycle to 15 munutes.
It's worked for a couple of days, and my battery voltage is running from 3.95V at sunrise to a little over 4V at sunset.
Feel free to give these a try! You'll need to download and install sunwait, and then change the lat/long, and also do the same thing for Astral in the setSkyCamNight.py script.
Any suggestions or improvements welcome! I'll post results here as we get on into winter
Here are the scripts: Sunset.sh #!/bin/sh /usr/local/bin/sunwait wait set 46.186555N 119.828222W /home/pi/bin/setSkyCamNight.py /home/pi/bin/upload_picture.sh /home/pi/SDL_Pi_SkyWeather2/static/CurrentPicture/A215.jpg Webcams/Sunset.jpeg
SetSkyCamNight.py #!/usr/bin/python3 # set SkyCam interval #
import json import paho.mqtt.client as mqtt import os import socket import sys import time import datetime from datetime import timedelta from astral import LocationInfo from astral.sun import sun
import traceback
MQTTCYCLECHANGE = 11
from subprocess import check_output
def on_publish(client, userdata, mid): print("published message",mid) client.disconnect() client.loop_stop() print("Exiting") sys.exit(0)
def on_log(client, userdata, level, buf): print("log: ",buf)
# The callback for when the client receives a CONNACK response from the server. def on_connect(client, userdata, flags, rc): print("Connected with result code "+str(rc)) # Subscribing in on_connect() means that if we lose the connection and # reconnect then subscriptions will be renewed. MyTopic = "SKYCAM"+"/"+cameraID+"/"+"INFO" def on_message(client, userdata, msg): print(msg.topic) print(msg.payload) try: if (cameraID != ""): SplitTopic = msg.topic SplitTopic = SplitTopic.split("/") if (((SplitTopic[1] == cameraID) or (cameraID == "+")) and (SplitTopic[2] == "INFO")): myMessage = json.loads(msg.payload) if (myMessage["messagetype"] == "4"): # last INFO message - SkyCam only listens for a short while sendMessage(client, cameraID, sendWhatCommand) except: traceback.print_exc()
def sendMessage(client, cameraID, messageType): # send command to SkyCameraRemote # get msg topic MyTopic = "SKYCAM"+"/"+cameraID+"/"+"COMMANDS" # set up JSON myIP = check_output(['hostname', '-I']) myIP = myIP.decode() myIP = myIP.replace("\n","") myIP = myIP.replace(" ","")
print("sending messagetype %s to:%s " %( messageType, MyTopic )) # send time to sleep message city = LocationInfo("Prosser", "WA", "America/Los_Angeles", 46.186555, -119.828222) now = datetime.datetime.now() tomorrow = now + timedelta(days=1) s = sun(city.observer, date=tomorrow, tzinfo=city.timezone) sleepTime = int((s["sunrise"].replace(tzinfo=None) - now).total_seconds()) myMessage = { "messagetype": MQTTCYCLECHANGE, "myip": myIP, "timetosleep": sleepTime }
myMessage = json.dumps(myMessage) client.publish(MyTopic, myMessage)
print("Messge Sent:",myMessage)
# main program
# what ID to test cameraID = "A215" # this command will be sent after an INFO messagetype 4 from cameraID sendWhatCommand = MQTTCYCLECHANGE
client = mqtt.Client() client.on_log=on_log client.on_connect = on_connect client.on_message = on_message client.on_publish = on_publish client.connect("localhost", port=1883)
# Blocking call that processes network traffic, dispatches callbacks and
# handles reconnecting. client.loop_forever()
Sunrise.sh #!/bin/sh #/usr/local/bin/sunwait wait rise 46.186555N 119.828222W /home/pi/bin/setSkyCamDay.py /home/pi/bin/upload_picture.sh /home/pi/SDL_Pi_SkyWeather2/static/CurrentPicture/A215.jpg Webcams/Sunrise.jpeg
SetSkyCamDay.py #!/usr/bin/python3 # set SkyCam interval #
import json import paho.mqtt.client as mqtt import os import socket import sys import time import datetime
import traceback
MQTTCYCLECHANGE = 11
from subprocess import check_output
def on_publish(client, userdata, mid): print("published message",mid) client.disconnect() client.loop_stop() print("Exiting") sys.exit(0)
def on_log(client, userdata, level, buf): print("log: ",buf)
# The callback for when the client receives a CONNACK response from the server. def on_connect(client, userdata, flags, rc): print("Connected with result code "+str(rc)) # Subscribing in on_connect() means that if we lose the connection and # reconnect then subscriptions will be renewed. MyTopic = "SKYCAM"+"/"+cameraID+"/"+"INFO" client.subscribe(MyTopic)
# The callback for when a PUBLISH message is received from the server. def on_message(client, userdata, msg): print(msg.topic) print(msg.payload) try: if (cameraID != ""): SplitTopic = msg.topic SplitTopic = SplitTopic.split("/") if (((SplitTopic[1] == cameraID) or (cameraID == "+")) and (SplitTopic[2] == "INFO")): myMessage = json.loads(msg.payload) if (myMessage["messagetype"] == "4"): # last INFO message - SkyCam only listens for a short while sendMessage(client, cameraID, sendWhatCommand) except: traceback.print_exc()
def sendMessage(client, cameraID, messageType): # send command to SkyCameraRemote # get msg topic MyTopic = "SKYCAM"+"/"+cameraID+"/"+"COMMANDS" # set up JSON myIP = check_output(['hostname', '-I']) myIP = myIP.decode() myIP = myIP.replace("\n","") myIP = myIP.replace(" ","")
print("sending messagetype %s to:%s " %( messageType, MyTopic )) # send time to sleep message myMessage = { "messagetype": MQTTCYCLECHANGE, "myip": myIP, "timetosleep": 890 }
myMessage = json.dumps(myMessage) client.publish(MyTopic, myMessage)
print("Messge Sent:",myMessage)
# main program
# what ID to test cameraID = "A215" # this command will be sent after an INFO messagetype 4 from cameraID sendWhatCommand = MQTTCYCLECHANGE
client = mqtt.Client() client.on_log=on_log client.on_connect = on_connect client.on_message = on_message client.on_publish = on_publish client.connect("localhost", port=1883)
# Blocking call that processes network traffic, dispatches callbacks and
# handles reconnecting. client.loop_forever()
|
|