Flashing DEEP-SLEEP-MODE Electron

Hi,

I put an Electron about two kilometres from my house. My program read an thermistor, publish value and go to deep sleep mode.

I prefer not to walk to my Electron, and since my Electron is not “alive” for long time :frowning:, I can’t flash it remotely (via cell).

Is it a command, or somethings else, that I can send to my Electron to wake up from deep sleep mode ?

Thanks

Mario

1 Like

If it’s asleep then, obviously, no. If you’re asleep, talking to you from 2km away isn’t going to help either. Deferred updates are in the works, and should hopefully be available sometime soon.

That said… for the time being, you might be able to use this. It’s a little Node.js script that will initiate a firmware update as soon as it receives an ‘online’ SSE from the specified device. To use it, save the code below in a file ‘server.js’, edit the file and enter your credentials. In that same directory issue npm install spark and npm install prompt. Download the firmware.bin file you want to flash to that directory.
From the command prompt run node server.js, then follow the prompts.

/*jslint node: true */
"use strict";

var spark = require('spark');
var prompt = require('prompt');
var openStream = function(ID, FirmwareName) {
  var shutDown = function() {
    process.exit();
  }

  var signalCb = function(err, data) {
    if (err) {
      console.log('An error occurred while flashing the device:', err);
    } else {
      console.log('Device flashing started successfully:', data);
      console.log("I'm gonna go bye bye now, deal with it.");

      setTimeout(shutDown, 3 * 1000);
    }
  };

  //Get your event stream
  var req = spark.getEventStream(false, 'mine', function(data) {
    //console.log(data);

    if (data.name == "spark/status" && data.data == "online") {
      console.log(data);
      console.log("going to flash the thingy...");
      spark.flashCore(ID, FirmwareName, signalCb);
    }
  });

  req.on('end', function() {
    console.log("ended!  re-opening in 3 seconds...");
    setTimeout(openStream, 3 * 1000);
  });
};
spark.on('login', function() {

  prompt.start();

  function onErr(err) {
    console.log(err);
    return 1;
  }
  prompt.get(['deviceID', 'Firmware'], function(err, result) {
    if (err) {
      return onErr(err);
    }
    console.log('Command-line input received:');
    console.log('  DeviceID: ' + result.deviceID);
    console.log('  Firmware: ' + result.Firmware);
    console.log('Waiting for device to come online.');
    openStream(result.deviceID, result.Firmware);
  });
});
// Login as usual
spark.login({
  username: 'email@provider.com',
  password: 'PASSWORD'
});
5 Likes

Again, you’re an infinity source of information ! Thanks @Moors7

1 Like

I send a UDP ping from Electron, then wait 10 seconds with process() for OTA update.

Or just stay awake for 1 minute every hour say for example from x:00 to x;01 using Time.minute().

Delayed updates has been described as a very important feature to have ready before electron for months by now, photon deep sleep users are suffering form the same issue.

Hopefully it will be here soon :alarm_clock:

If you use your own server in combination with the electron/photon, one option is to publish a value to indicate theres a update waiting.
So when the device awakens(or every x wakeups) it checks update_pending flag, if its not 0, then it waits for one minute before going to sleep.
The script that displays this flag to the device will then call particle cloud and initiate the software download, and upon confirmation from the device that update went ok, reset the flag to 0.

2 Likes

Hi,

I just use thingspeak as data storage. I got a Photon to read the channel #8 value, if its higher than 0 it resets this channel value, turns on particle-cloud and doesn’t go to sleep mode for next 2 hours.

The same code obviously didn’t work using Electron - maybe because of an TCPclient-bug with very small responses.

“Delayed” updates would be much nicer, it would be possible to send the electron in deep sleep mode for hours and check for new updates just once a day.

regards