I’ve been tinkering around with my Electron and trying to send data via Publish, which hits a webhook and sends it to the aggregation service I’m using. I currently have it publishing it’s Battery Level (SoC) to the aggregation service, sleeping for 20 minutes, and then publishing again. I was doing it to learn a bit more about publish/webhooks and to get a ballpark of the electron’s battery drainage…but for some reason only the first two publishes work! The timeline is something like this:
Flash Electron via USB/Particle CLI --> Run through loop, publish SoC value --> SLeep for 20 minutes (In “Stop” Mode) --> Wake up, wait for Particle.connected, Publish --> Sleep for 20 min -->???
I’ve tried two aggregation services (Both Librato and Adafruit IO), and it stops after the second publish for both services. Below is my code:
OK, that did not work after the first wake up from sleep.
Trying this code now which is closer to what your doing:
#include "application.h"
FuelGauge fuel;
char publishStr[20];
int led2 = D6; // Instead of writing D7 over and over again, we'll write led2
// This one is the little blue LED on your board. On the Photon it is next to D7, and on the Core it is next to the USB jack.
Thanks. I’ve tried a few different tweaks but to no avail. I pulled up the events stream for my electron via curl, and I can confirm the first two publishes go out just fine, but I never see any more than that second publish. I wanted to make sure that it was just publish that was having issues, and not webhook or the aggregation services, and it seems like it is the sleep/publish combo.
Yea I’m seeing it publish after the 2nd wakeup but then the next 2 publishes do not show up, then the next publish will show up.
I added a 2 second delay after the waitUntil(Particle.connected); but it’s not solving the issue.
I’m going to keep playing around but we should see what @Bdub has to say.
@BDub can you give this a try and see what you can find out?
The Publish using no sleep mode seems to be stable, but when you start publishing after waking up from sleep some publishes go missing for some reason.
Hey all! I have been trying to spread the word that sleep (Stop) mode and waking are not going to be working exactly as desired until the next Electron firmware release:
Basically the modem is being power cycled when sleeping currently, and when waking we are also not notifying the server that the IP address may have changed (which it likely has). These things are fixed already, but need to be merged and released. Soon! Thanks for your patience until it's out
@bdub I’ll have never built locally so it will be all new to me so excuse my ignorance on the following question.
If I get setup to build locally I will be able to compile your latest firmware and also add in the PR change you linked to above to fix the current sleep publish issue right? Just want to make sure.
And if I just want to wait for the latest firmware do you have any idea when we could expect to see it?
@bpr Let me know if you add the fix code and get it working.
You can create a new branch based on develop, then merge the feature/electron/sleep-resume branch into it:
git clone https://github.com/spark/firmware.git
git checkout develop
git checkout -b test/sleep
git merge feature/electron/sleep-resume
vi editor is likely going to pop up
type `:wq` and hit ENTER
now you can compile from the modules directory
firmware/modules $ make clean all PLATFORM_ID=10 APPDIR=~/fw-apps/my-sleep-app DEBUG_BUILD=y COMPILE_LTO=n PARTICLE_DEVELOP=1 -s program-dfu
put your app named whatever.cpp in the ~/fw-apps/my-sleep-app/ folder
@BDub@RWB I got an error on the fourth command “C:\particle\developmerge>git merge feature/electron/sleep-resume
merge: feature/electron/sleep-resume - not something we can merge” (I’m on Windows 10)
so I just manually added those two lines (49 and 51) to system_sleep.cpp and compiled from modules and my electron started pumping out beautiful little events as desired every minute under stop mode
However, the only problem is that after 5 publish events the dashboard often but not always starts showing 2 identical events either at identical times or near identical (e.g., one at 2016-02-23T05:09:34.825Z the other at 2016-02-23T05:09:34.826Z)
Just to be clear the first test was meant to be every minute, just not multiple events per minute.
I’m going to change the interval to every 30 minutes and go to bed, see what’s up in the morning
I started testing your code every 10 minutes and got to 2 publishes with no issue and decided I want to sleep soon so I changed it to every 1 minute just now We’ll see some results hopefully quickier
So I wasn’t seeing a double publish, but when I started looking at the local Serial1 logs things didn’t look right because we’re not waiting for ACK from the server before we sleep, so when we wake back up the first thing that was happening is the ACK would appear to be received, even though it already happened and was just in the buffer.
I added this before the Sleep call and logs cleared up, one publish, one acknowledge over and over.
With the PR, running the 30-minute interval stop-mode sleep app overnight yielded no double publishes in the dashboard but it appears data usage was higher than when not using sleep mode at all the day before, but I can’t be too sure about the data usage given that the report is delayed and just now the dash says my "billing info is not available… please check back…"
Curious how I was getting that double publish (actually sometimes triple) at much shorter interval. @BDub, I’m very glad you found the likely problem. Thanks!
So I tried adding in this delay, and it worked while I had my sleep time set to two minutes! But I tried everything the same but increasing the sleep delay back to 1200 secs, and now I"m only getting the first publish, and nothing further. Very strange.