Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Copyright 2017, Helium Systems, Inc.
- * All Rights Reserved. See LICENCE.txt for license information
- */
- #include "Arduino.h"
- #include "Board.h"
- #include "Helium.h"
- #include "HeliumUtil.h"
- #define CHANNEL_NAME "googleiot-test"
- #define CONFIG_INTERVAL_KEY "channel.interval_ms"
- #define CONFIG_STATE_KEY "channel.state"
- Helium helium(&atom_serial);
- Channel channel(&helium);
- Config config(&channel);
- int32_t send_interval;
- int32_t state = 2;
- void
- update_config(bool stale)
- {
- if (stale)
- {
- DBG_PRINT(F("Fetching Config - "));
- int status = config.get(CONFIG_INTERVAL_KEY, &send_interval, 5000);
- // report_status(status);
- status = config.get(CONFIG_STATE_KEY, &state, 2);
- report_status(status);
- if (status == helium_status_OK)
- {
- DBG_PRINT(F("Updating Config - "));
- status = config.set(CONFIG_INTERVAL_KEY, send_interval);
- // report_status(status);
- status = config.set(CONFIG_STATE_KEY, state);
- report_status(status);
- }
- }
- }
- void
- setup()
- {
- Serial.begin(9600);
- DBG_PRINTLN(F("Starting"));
- helium.begin(HELIUM_BAUD_RATE);
- // Connect the Atom to the Helium Network
- helium_connect(&helium);
- // and do a channel connect
- channel_create(&channel, CHANNEL_NAME);
- // Get the initial interval
- update_config(true);
- }
- void
- loop()
- {
- const char * data = "Hello Helium!";
- Serial.println(state);
- switch(state) {
- case 1:
- channel_send(&channel, CHANNEL_NAME, data, strlen(data));
- // Wait till the next time
- delay(send_interval);
- break;
- case 2:
- Serial.println("idle");
- // Wait till the next time
- delay(send_interval);
- break;
- default:
- Serial.println("defaulting");
- }
- update_config(true);
- }
Add Comment
Please, Sign In to add comment