Advertisement
Guest User

Untitled

a guest
Jun 24th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.42 KB | None | 0 0
  1. //Main Code
  2.  
  3.  
  4. #include <SoftwareSerial.h>
  5.  
  6.  
  7. #include <Bridge.h>
  8. #include <Temboo.h>
  9. #include "TembooAccount.h"
  10.  
  11.  
  12. String ADDRESS_FOR_FORECAST = "Cheongju, CJ"; //Enter zipcode for where you want to check the weather (or city,state)
  13.  
  14. int numRuns = 1; // execution count, so that this doesn't run forever
  15. int maxRuns = 10; // max number of times the Yahoo WeatherByAddress Choreo should be run
  16.  
  17.  
  18. int outputPin : 13;
  19. int inputPin : 8;
  20.  
  21.  
  22. void setup() {
  23. Serial.begin(9600);
  24. delay (4000)
  25.  
  26. while(|Serial);
  27. Bridge.begin();
  28.  
  29. pinMode(outputPin, OUTPUT);
  30. pinMode(inputPin, INPUT);
  31.  
  32. Serial.println("Setup complete.\n");
  33. }
  34.  
  35.  
  36.  
  37.  
  38. void loop()
  39. {
  40. int sensorValue = digitalRead(inputPin);
  41. Serial.println("Sensor: " + String(sensorValue));
  42.  
  43. if (sensorValus == HIGH) {
  44. if (calls < maxCalls) {
  45. Serial.println("\nTriggered| Calling GetWeather");
  46. }
  47. }
  48. // while we haven't reached the max number of runs...
  49. if (numRuns <= maxRuns) {
  50.  
  51. // print status
  52. Serial.println("Running GetWeatherByAddress - Run #" + String(numRuns++) + "...");
  53.  
  54. // create a TembooChoreo object to send a Choreo request to Temboo
  55. TembooChoreo GetWeatherByAddressChoreo;
  56.  
  57. // invoke the Temboo client
  58. GetWeatherByAddressChoreo.begin();
  59.  
  60. // add your temboo account info
  61. GetWeatherByAddressChoreo.setAccountName(TEMBOO_ACCOUNT);
  62. GetWeatherByAddressChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);
  63. GetWeatherByAddressChoreo.setAppKey(TEMBOO_APP_KEY);
  64.  
  65. // set the name of the choreo we want to run
  66. GetWeatherByAddressChoreo.setChoreo("/Library/Yahoo/Weather/GetWeatherByAddress");
  67.  
  68. // set choreo inputs; in this case, the address for which to retrieve weather data
  69. // the Temboo client provides standardized calls to 100+ cloud APIs
  70. GetWeatherByAddressChoreo.addInput("Address", ADDRESS_FOR_FORECAST);
  71.  
  72. // add an output filter to extract the name of the city.
  73. GetWeatherByAddressChoreo.addOutputFilter("city", "/rss/channel/yweather:location/@city", "Response");
  74.  
  75. // add an output filter to extract the current temperature
  76. GetWeatherByAddressChoreo.addOutputFilter("temperature", "/rss/channel/item/yweather:condition/@temp", "Response");
  77.  
  78. // add an output filter to extract the date and time of the last report.
  79. GetWeatherByAddressChoreo.addOutputFilter("date", "/rss/channel/item/yweather:condition/@date", "Response");
  80.  
  81. // run the choreo
  82. GetWeatherByAddressChoreo.run();
  83.  
  84. // parse the results and print them to the serial monitor
  85. while(GetWeatherByAddressChoreo.available()) {
  86. // read the name of the next output item
  87. String name = GetWeatherByAddressChoreo.readStringUntil('\x1F');
  88. name.trim(); // use “trim” to get rid of newlines
  89.  
  90. // read the value of the next output item
  91. String data = GetWeatherByAddressChoreo.readStringUntil('\x1E');
  92. data.trim(); // use “trim” to get rid of newlines
  93.  
  94. while (name == "temperature") {
  95. int temp = data.toInt(); // THE GOOD STUFF (variable temp = temperature!!)
  96. Serial.println(temp); // Print the Temperature
  97.  
  98.  
  99.  
  100. break;
  101. }
  102.  
  103.  
  104. }
  105.  
  106. Serial.println("");
  107. Serial.println("Waiting...");
  108. Serial.println("");
  109. delay(10000); // wait 10 seconds between GetWeatherByAddress calls
  110. }
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement