Created
September 11, 2018 21:18
-
-
Save isheraz/898fd8c8d495d259170f5a9ae5cc47d4 to your computer and use it in GitHub Desktop.
for Lucas to use with beerontaps.com
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <ESP8266WiFi.h> | |
#include <ESP8266HTTPClient.h> | |
#include <ArduinoJson.h> | |
const char* ssid = "509 Pak Block"; | |
const char* ssidPassword = "IKnowSomethings12"; | |
DynamicJsonBuffer jsonBuffer; | |
HTTPClient http; | |
void setup() { | |
Serial.begin(9600); | |
WiFi.mode(WIFI_STA); | |
WiFi.begin(ssid, ssidPassword); | |
while (WiFi.status() != WL_CONNECTED) { | |
delay(500); | |
Serial.print("."); | |
} | |
Serial.println(""); | |
Serial.println("WiFi connected"); | |
Serial.println("IP address: "); | |
Serial.println(WiFi.localIP()); | |
// char json[300]; | |
// Post RequestStart | |
http.begin("http://beerontaps.com/api/rfid/update"); | |
http.addHeader("Content-Type", "application/json"); | |
String req ="{\"rfid\": \"577d8s89\",\"value\": 20,\"serial\": \"zXb31S96\",\"quantity\": 500}"; | |
Serial.println(req); | |
http.POST( req); | |
http.writeToStream(&Serial); | |
http.end(); | |
// Post Request Ends | |
} | |
void loop() { | |
Serial.flush(); | |
http.begin("http://beerontaps.com/api/rfid/53753d27?serial=mEE6zakn"); //Get Request to fetch all data in json format | |
http.addHeader("Content-Type", "application/json"); | |
http.GET(); | |
String payload = http.getString(); | |
Serial.print(payload); | |
if(payload.length() > 0){ | |
Serial.println(payload); | |
Serial.println(http.getString()); | |
JsonObject& root = jsonBuffer.parseObject(payload); | |
// // Test if parsing succeeds. | |
if (!root.success()) { | |
Serial.println("parseObject() failed"); | |
return; | |
}else{ | |
Serial.println("Data Fetched"); | |
Serial.print("Name: "); | |
Serial.println(root[String("person")][String("name")].as<const char*>()); | |
Serial.print("Amount: "); | |
Serial.println(root["person"]["value"].as<const char*>()); | |
Serial.print("Drink Name: "); | |
Serial.println(root[String("tap")]["drink_name"].as<const char*>()); | |
} | |
}else{ | |
Serial.println("Payload Empty"); | |
} | |
http.end(); | |
delay(10000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment