Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reduce datausage on reset/wakeup #953

Merged
merged 6 commits into from Jun 6, 2016

Conversation

@m-mcgowan
Copy link
Contributor

commented Apr 11, 2016

Reduces data consumption when the device is reset or wakes up from deep sleep.

Computes a checksum of the last set of subscriptions, functions, variables and system modules that were sent to the cloud, which is maintained in retained storage, as part of the session.

Before sending a hello after resuming the session, the device checks the current checksum for the subscriptions, functions variables and system modules. If it is the same as the persisted checksum, the hello message is stkipped, since the local application state is the same as what was last sent to the cloud. When the checksums are not the same, the hello message is sent, which clears the app state on the server, so all subsequent describe messages and subscriptions are resent.

For this to work optimally, code should use SEMI_AUTOMATIC mode and connect to the cloud after registering all subscriptions, variables and functions.

e.g.

SYSTEM_MODE(SEMI_AUTOMATIC);

void setup()
{
     Particle.function(...); 
     Particle.subscribe(...);
     Particle.variable(...);

    Particle.connect();
}


Doneness:

  • Contributor has signed CLA
  • Problem and Solution clearly stated
  • Code peer reviewed
  • API tests compiled
  • Run unit/integration/application tests on device
  • Add documentation
  • Add to CHANGELOG.md after merging (add links to docs and issues)

@m-mcgowan m-mcgowan added this to the 0.6.x milestone Apr 11, 2016

@m-mcgowan m-mcgowan force-pushed the feature/deep_sleep_data_usage branch from ab6b6b0 to 6c072f4 Apr 26, 2016

@m-mcgowan

This comment has been minimized.

Copy link
Contributor Author

commented Apr 26, 2016

Test app:

#include "Particle.h"

SYSTEM_MODE(SEMI_AUTOMATIC);
STARTUP(System.enableFeature(FEATURE_RETAINED_MEMORY));

int valueInt = 0;

void handler(String name, String value)
{
}

int increment(String args)
{
    return ++valueInt;
}

void setup()
{
    Particle.subscribe("hello", handler, MY_DEVICES);
    Particle.variable("value", valueInt);
        Particle.function("inc", increment);
    Cellular.on();
    Cellular.resetDataUsage();
    Cellular.connect();
}

void showDataUsage()
{
    CellularData data;
    Cellular.getDataUsage(data);

    Serial.print("data usage:");
    Serial.println(data);
}

void loop()
{
    if (Serial.available())
    {
        char c = Serial.read();
        switch (c)
        {
        case 'C':
            Particle.connect();
            waitUntil(Particle.connected);
            break;
        case 'd':
            showDataUsage();
            break;
        case 'r':
            System.reset();
            break;
        case 's':
            System.sleep(SLEEP_MODE_DEEP, 120, SLEEP_NETWORK_STANDBY);
            break;
        case 'c':
            Particle.disconnect();
            break;
        }
    }
}

Verify data usage reduction test:

  1. flash the app to your Electron by compiling in the cloud against 0.5.0 (production)
  2. power down fully, then power on. The device will connect and breathe green.
  3. connect to serial, and press 'd' and verify data usage is 0. (Only connected to tower.)
  4. press 'C' to connect to the cloud, and then 'd' to retrieve the data usage.
  5. press 's' to deep sleep the device
  6. press reset to wake up the device and reconnect to serial
  7. press 'd' , and verify data usage to connect to the tower is 0 (as measured by the device.)
  8. press 'C' to connect to the cloud, and then 'd' to retrieve the warm boot data usage.
  9. flash system firmware from this PR, and recompile the test app locally
  10. repeat these steps and verify the data usage on warm boot is significantly less.

Test results (mdma):

# running against 0.5.0 system firmware
# start from power-down
# connect to cellular data usage: *d*
data usage:31,0,0,0,0
# cold connect to cloud data usage: *C*
data usage:31,2671,2257,2671,2257
# sleep: *s*, reset
# connect to cellular data usage: *d*
data usage:31,0,0,0,0
# warm connect to cloud data usage: *C*
data usage:31,2673,2257,2673,2257

# running against this PR
# start from power-down
# connect to cellular data usage: *d*
data usage:31,0,0,0,0
# cold connect to cloud data usage: *C*
data usage:31,2737,2325,2737,2325
# sleep: *s*, reset
# connect to cellular: *d*
data usage:31,0,0,0,0
# warm connect to cloud data usage: *C*
data usage:31,74,61,74,61

Additional tests:

  • flash tinker, verify funcs/vars, flash another app and verify they change

@m-mcgowan m-mcgowan assigned m-mcgowan and unassigned technobly Apr 26, 2016

@monkbroc monkbroc removed the in progress label Apr 27, 2016

@m-mcgowan m-mcgowan force-pushed the feature/deep_sleep_data_usage branch from fa37c46 to 04fc5de May 26, 2016

@m-mcgowan

This comment has been minimized.

Copy link
Contributor Author

commented May 26, 2016

@technobly - this one's ready for review.

m-mcgowan and others added 6 commits Apr 11, 2016
computes a checksum of the last set of subscriptions, functions, vari…
…ables and system modules that were sent to the cloud. Before sending a hello after resuming the session, the device checks the current checksum for the subscriptions, functions variables and system modules. If it is the same, the hello message is stkipped. When the checksums are not the same, the hello message is sent, which clears the app state on the server, so all subsequent describe messages and subscriptions are resent.
ensures the retained system variables are stored in the system region…
… of backup ram. This can be verified by

```
$ arm-none-eabi-nm system-part2.elf | grep "D session"
40024c00 D session
```

Regular RAM starts at address 0x20000000, while the system reserved area in backup ram is a 0x40024c00 (3K offset from the start of backup ram.)

@m-mcgowan m-mcgowan force-pushed the feature/deep_sleep_data_usage branch from 9f8f42c to 2e12943 Jun 6, 2016

@m-mcgowan m-mcgowan merged commit 37411a8 into develop Jun 6, 2016

0 of 2 checks passed

continuous-integration/travis-ci/pr The Travis CI build is in progress
Details
continuous-integration/travis-ci/push The Travis CI build is in progress
Details
m-mcgowan added a commit to particle-iot/firmware-docs that referenced this pull request Jun 7, 2016
reduce datausage on reset/wakeup (#953)
* computes a checksum of the last set of subscriptions, functions, variables and system modules that were sent to the cloud. Before sending a hello after resuming the session, the device checks the current checksum for the subscriptions, functions variables and system modules. If it is the same, the hello message is stkipped. When the checksums are not the same, the hello message is sent, which clears the app state on the server, so all subsequent describe messages and subscriptions are resent.

* adding final touches to docs

* ensures the retained system variables are stored in the system region of backup ram. This can be verified by
```
$ arm-none-eabi-nm system-part2.elf | grep "D session"
40024c00 D session
```

Regular RAM starts at address 0x20000000, while the system reserved area in backup ram is a 0x40024c00 (3K offset from the start of backup ram.)

* documentation advising how to get the lowest possible data use when reconnecting to the cloud.

* reworked the docs

* adds changelog for particle-iot/device-os#953

@technobly technobly deleted the feature/deep_sleep_data_usage branch Oct 27, 2016

technobly added a commit that referenced this pull request Dec 22, 2016
Squashed 'docs/reference/' changes from e5391c4..a892020
a892020 unifying Since x.x.x firmware version messages
b153672 Since 0.7.0 -> Since 0.6.1
52a6313 Merge commit '60e0e09d54c2b5c1ebe875861da77a306d3c785b' into prerelease-dup
9dac290 More typos fixed
5295a53 corrected grammar (#524)
9f4b24b Spell check docs
fcca5c6 occaisonal --> occasional
60e0e09 Reference documentation
ef0dad7 Merge pull request #1190 from spark/feature/setup-button-mirror
d2eb670 Merge pull request #1195 from spark/fix/revert_publish_api
05d0200 Merge branch 'develop' into feature/listen-timeout
2b43c71 grammatical error
878ba19 Revert Particle.publish() API changes; docs for WITH_ACK flag
b7030c5 Update firmware.md
d84a942 Add advanced process control
fa03d96 Fix broken link on firmware page
03b8a78 Document Process::run
08047a0 EEPROM is borken on RPi
566a869 buttonMirror() documentation
ea100c7 Support for `Serial1` is not complete
468b33d Raspberry Pi I2C firmware docs
32e5ba4 Remove software timers from RPi docs.
26d7251 Merge branch 'develop' into feature/conn_state_events
e15b410 added v0.6.0 firmware notes
38614db adds Docs for set|getListenTimeout()
9949e2d adds usb-serial1 device tags
eee29b2 cleanup serial2 and manual edits from last merge with conflicts
616330f Merge branch 'master' into prerelease
4590339 Update firmware docs to use device features
8e1149f Add device feature flags
62312f0 Add Raspberry Pi to firmware, tools and guides
7168402 Update firmware.md
c93d248 Clarification of retained SRAM size
73f2e00 corrected typo 'sequencially' to 'sequentially'
648234c Merge pull request #468 from spark/feature/usb-docs-0.6.0
d3e5eba Reference docs
7794203 Merge branch 'master' into prerelease
edcf989 adds link to freertos4core particle library
1ffdd80 time_changed system event
dbc5d03 Time.isValid(), Particle.syncTimeDone()/syncTimePending()/timeSyncedLast() documentation
c380dfd [optional] needs to include the optional comma too
6f5c96d Merge branch 'master' into prerelease
6cf14d1 Update firmware.md
6e6e216 Merge branch 'master' into prerelease
f2cf630 adding notes for 0.5.1 and 0.5.2 firmware versions
6249120 adds reference.hbs back to firmware.md
6fa5464 ensure firmwareversions.js only loads on firmware.md aka firmware reference
4fc16b8 added CLI version, electron part 2/3 options and downgrading instructions
ad530eb Separate Firmware Release and Formatting Tweaks
aafbabe Create possibility for passing variables thorugh query params, for Firmware Releases
25cab35 Fixes typo
1aa4c18 Add B0-B5, C0-C5 to GPIO list in note for electron
c857e8a Merge branch 'master' into prerelease
dac4690 Keyboard and Mouse documentation
8d974bf Updated Serial documentation
fd24a4d Merge pull request #467 from dougalcampbell/patch-1
4d75a59 Missing doc for TCPClient(buffer, len)
1b667e5 Use `hostname` instead of `URL` terminology
d0e5903 Merge commit '568ceade3e1481cdb00dcdf51a97a737750a96bb' from firmware-docs into staging
d49ac39 Merge branch 'master' into feature/tutorials
e205803 Makes tests pass, fixing broken dashboard links
66a1955 Fix your product id link
81f7eb6 More Dashboard -> Console
266e459 fixed: markdown for threading docs
4f615c9 missing markdown for interrupts example
568cead Daylight Saving Time (DST) documentation
a696d8a new analogRead() pinMode behavior for 0.5.3 system firmware
aa2994a Fix description of sleep(pin, edge)
5c049dc fix typos
b69e421 Typo in SoftAP example
be62c64 Clarify behavior of 0 seconds in System.sleep() (#425)
838d6c7 missing parameters for printlnf()
7503310 relocated note
62acc8d missed # in condition 😊
f50a589 Update firmware.md
7bc380b Note WKP for deep sleep
af77e5e Merge branch 'feature/reset-network-flag' into develop
405e9e9 Documentation fixes
0415ab4 API docs
0e0a691 Minor fixes
53f993b API docs for logging attributes
18483a2 Merge pull request #991 from spark/feature/dac-pwm-resolution
747f8d0 Merge pull request #997 from spark/feature/serial-config
26eaba8 Merge pull request #998 from spark/feature/logger_api
b7f3081 Update flush() documentation
af32b6b Store last reset reason and publish it to the cloud (#944)
08d2d42 USART configuration documentation
20ebf60 API docs
29e91a1 reduce datausage on reset/wakeup (#953)
6665b03 typo
4caa81c One carriage return isn't enough to make a new paragraph (#414)
a4f05d6 Fix typo in handlebar if
c790bcb Take out factory reset for anything but the Core
d41c053 WIFI_CONNECT_NO_LISTEN actually is WIFI_CONNECT_SKIP_LISTEN
4db5752 Increase documented number of cloud functions and variables (#397)
80ff0e9 Add PRODUCT_ID to the firmware docs
dc99c6e Reword cloud function #389
66f4acf analogWriteResolution documentation
3602095 Fix layout in Serial.begin()
df96c32 Clarify include header for Serial2
761f7c4 explicitly show the particle.function protype
6667d16 add a single letter, whenver->whenever
79ea057 Wire.stretchClock() feature enabled by default for I2C Slave mode
f3ad8b5 made firmware.md a symlnk on linux...didn't take on OS X

git-subtree-dir: docs/reference
git-subtree-split: a892020dc28f10d348c813f63e77099993ecf5f6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.