Advertisement
Guest User

testing-webhook.ino

a guest
Aug 24th, 2015
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.87 KB | None | 0 0
  1. #include "tinyxml2.h";
  2. String response = "";
  3.  
  4. void setup() {
  5.     Serial.begin(9600);
  6.  
  7.     Particle.subscribe("hook-response/get_weather", gotWeatherData, MY_DEVICES);
  8.  
  9.     for(int i=0;i<3;i++) {
  10.         Serial.println("waiting " + String(3-i) + " seconds before we publish");
  11.         delay(1000);
  12.     }
  13. }
  14.  
  15. void loop() {
  16.     response = "";
  17.  
  18.     Serial.println("Requesting Weather!");
  19.  
  20.     Particle.publish("get_weather");
  21.  
  22.     delay(60000);
  23. }
  24.  
  25. void gotWeatherData(const char *name, const char *data) {
  26.     Serial.println("Consolidating data");
  27.  
  28.     String str = String(data);
  29.  
  30.     response = String(response + data);
  31.  
  32.     // If you feel you got it all, start parsing
  33.     if( str.indexOf("</current>") != -1 ) {
  34.         Serial.println(response);
  35.         parseResponse();
  36.     }
  37. }
  38.  
  39. String parseResponse() {
  40.     Serial.println("Parsing data");
  41.     return 1;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement