Advertisement
Guest User

PEKA API

a guest
Dec 16th, 2017
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.74 KB | None | 0 0
  1. #include <ESP8266HTTPClient.h>
  2. #include <ESP8266WiFi.h>
  3. #include <ArduinoJson.h>
  4.  
  5. const char* ssid = "SSID";
  6. const char* password = "PASS";
  7.  
  8. void setup() {
  9.   // put your setup code here, to run once:
  10.     Serial.begin(115200);
  11.   WiFi.begin(ssid, password);
  12.   while (WiFi.status() != WL_CONNECTED) {
  13.     delay(500);
  14.     Serial.print(".");
  15.   }
  16.   Serial.println("WiFi connected");
  17.  
  18. }
  19.  
  20. StaticJsonBuffer<4096> jsonBuffer;
  21.  
  22. void loop() {
  23.   // put your main code here, to run repeatedly:
  24.  
  25.  if(WiFi.status()== WL_CONNECTED){   //Check WiFi connection status
  26.  
  27.    HTTPClient http;    //Declare object of class HTTPClient
  28.  
  29.   // http.begin("https://www.peka.poznan.pl/vm/method.vm?ts=1506284957537&method=getTimes&p0={\"symbol\":\"SWCZ72\"}");      //Specify request destination
  30.    http.begin("http://www.peka.poznan.pl/vm/method.vm?ts=1506284957537&method=getTimes&p0={\"symbol\":\"SWCZ72\"}");
  31.    int httpCode = http.POST("");   //Send the request
  32.    String payload = http.getString();                  //Get the response payload
  33.    Serial.println(httpCode);   //Print HTTP return code
  34.    Serial.println(payload);   //Print request response payload
  35.    JsonObject& root = jsonBuffer.parseObject(payload.c_str());
  36.    //char test_payload[] =
  37.   if (!root.success()) {
  38.     Serial.println(F("Parsing failed!"));
  39.   } else {
  40.     Serial.println(F("SUCCESS!"));
  41.     const char* response = root["success"];
  42.     JsonObject& root2 = jsonBuffer.parseObject(response);
  43.     if (!root2.success()) {
  44.       Serial.println(F("Parsing failed!"));
  45.     } else {
  46.     Serial.println(response);}
  47.   }
  48.  
  49.    http.end();  //Close connection
  50.  
  51.  }else{
  52.  
  53.     Serial.println("Error in WiFi connection");  
  54.  
  55.  }
  56.  
  57.   delay(30000);  //Send a request every 30 seconds
  58.  
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement