Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <ESP8266HTTPClient.h>
- #include <ESP8266WiFi.h>
- #include <ArduinoJson.h>
- const char* ssid = "SSID";
- const char* password = "PASS";
- void setup() {
- // put your setup code here, to run once:
- Serial.begin(115200);
- WiFi.begin(ssid, password);
- while (WiFi.status() != WL_CONNECTED) {
- delay(500);
- Serial.print(".");
- }
- Serial.println("WiFi connected");
- }
- StaticJsonBuffer<4096> jsonBuffer;
- void loop() {
- // put your main code here, to run repeatedly:
- if(WiFi.status()== WL_CONNECTED){ //Check WiFi connection status
- HTTPClient http; //Declare object of class HTTPClient
- // http.begin("https://www.peka.poznan.pl/vm/method.vm?ts=1506284957537&method=getTimes&p0={\"symbol\":\"SWCZ72\"}"); //Specify request destination
- http.begin("http://www.peka.poznan.pl/vm/method.vm?ts=1506284957537&method=getTimes&p0={\"symbol\":\"SWCZ72\"}");
- int httpCode = http.POST(""); //Send the request
- String payload = http.getString(); //Get the response payload
- Serial.println(httpCode); //Print HTTP return code
- Serial.println(payload); //Print request response payload
- JsonObject& root = jsonBuffer.parseObject(payload.c_str());
- //char test_payload[] =
- if (!root.success()) {
- Serial.println(F("Parsing failed!"));
- } else {
- Serial.println(F("SUCCESS!"));
- const char* response = root["success"];
- JsonObject& root2 = jsonBuffer.parseObject(response);
- if (!root2.success()) {
- Serial.println(F("Parsing failed!"));
- } else {
- Serial.println(response);}
- }
- http.end(); //Close connection
- }else{
- Serial.println("Error in WiFi connection");
- }
- delay(30000); //Send a request every 30 seconds
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement