Guest User

Untitled

a guest
Dec 11th, 2017
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. /*
  2. * Copyright 2017, Helium Systems, Inc.
  3. * All Rights Reserved. See LICENCE.txt for license information
  4. */
  5.  
  6. #include "Arduino.h"
  7. #include "Board.h"
  8. #include "Helium.h"
  9. #include "HeliumUtil.h"
  10.  
  11. #define CHANNEL_NAME "googleiot-test"
  12. #define CONFIG_INTERVAL_KEY "channel.interval_ms"
  13. #define CONFIG_STATE_KEY "channel.state"
  14.  
  15. Helium helium(&atom_serial);
  16. Channel channel(&helium);
  17. Config config(&channel);
  18.  
  19. int32_t send_interval;
  20. int32_t state = 2;
  21. void
  22. update_config(bool stale)
  23. {
  24. if (stale)
  25. {
  26. DBG_PRINT(F("Fetching Config - "));
  27. int status = config.get(CONFIG_INTERVAL_KEY, &send_interval, 5000);
  28. // report_status(status);
  29.  
  30. status = config.get(CONFIG_STATE_KEY, &state, 2);
  31. report_status(status);
  32.  
  33. if (status == helium_status_OK)
  34. {
  35. DBG_PRINT(F("Updating Config - "));
  36. status = config.set(CONFIG_INTERVAL_KEY, send_interval);
  37. // report_status(status);
  38. status = config.set(CONFIG_STATE_KEY, state);
  39. report_status(status);
  40. }
  41. }
  42. }
  43.  
  44. void
  45. setup()
  46. {
  47. Serial.begin(9600);
  48. DBG_PRINTLN(F("Starting"));
  49. helium.begin(HELIUM_BAUD_RATE);
  50.  
  51. // Connect the Atom to the Helium Network
  52. helium_connect(&helium);
  53. // and do a channel connect
  54. channel_create(&channel, CHANNEL_NAME);
  55.  
  56. // Get the initial interval
  57. update_config(true);
  58. }
  59.  
  60.  
  61. void
  62. loop()
  63. {
  64. const char * data = "Hello Helium!";
  65. Serial.println(state);
  66. switch(state) {
  67. case 1:
  68. channel_send(&channel, CHANNEL_NAME, data, strlen(data));
  69. // Wait till the next time
  70. delay(send_interval);
  71. break;
  72. case 2:
  73. Serial.println("idle");
  74. // Wait till the next time
  75. delay(send_interval);
  76. break;
  77. default:
  78. Serial.println("defaulting");
  79. }
  80. update_config(true);
  81. }
Add Comment
Please, Sign In to add comment