Skip to content

Instantly share code, notes, and snippets.

@refugeesus
Created December 8, 2017 17:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save refugeesus/aceaf124edee4dbb29c8eca1e81ca853 to your computer and use it in GitHub Desktop.
Save refugeesus/aceaf124edee4dbb29c8eca1e81ca853 to your computer and use it in GitHub Desktop.
/*
* 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);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment