The entire tutorial makes an HTTP client for uploading Yeelink data points.
1 Get Account http://www.cnblogs.com/imfanqi/p/4419915.html
2 Code Tutorial http://www.windworkshop.cn/?p=1217
#include <ESP8266WiFi.h> #include <ESP8266HTTPClient.h> #define UKEY ""//Yeelink provided u-apikeystring SSID = "" ; Need to connect the WiFi hotspot name string password = ""; Need to connect the WiFi hotspot password/* Upload data to the server. * Device is the unit number, sensor number, data is the value of the upload point * here the default is uploaded to the latest data points, the need to upload to a specific point in the post content to be added separately timestamp */void uploadyeelinkdata (String Device, string sensor, string data) {HTTPClient http; Const String apiaddress = "/v1.1/device/" + device + "/sensor/" + sensor + "/datapoints"; Http.begin ("Api.yeelink.net", apiaddress); Http.addheader ("U-apikey", Ukey, True); int httpcode = http. POST ("{\" value\ ":" + Data + "}"); Serial.print ("code:"); Serial.println (Httpcode); if (Httpcode = = 200) {//Access succeeded, get return parameter String payload = http.getstring (); SERIAL.PRINTLN (payload); } else {//access is unsuccessful, print reason String payload = http.getstring (); Serial.print ("Context:"); SERIAL.PRINTLN (payload); }}/* data from the server * device is the unit number, sensor number */void Readyeelinkdata (string device, String sensor) {HTTPClient http; The API used hereIs v1.0, v1.1 API needs to provide U-apikey const String apiaddress = "/v1.0/device/" + device + "/sensor/" + sensor + "/datapoints"; Http.begin ("Api.yeelink.net", apiaddress); int httpcode = http. GET (); Use get form to get Data Serial.print ("code:"); Serial.println (Httpcode); if (Httpcode = = 200) {//Access succeeded, get return parameter String payload = http.getstring (); SERIAL.PRINTLN (payload); } else {//access is unsuccessful, print reason String payload = http.getstring (); Serial.print ("Context:"); SERIAL.PRINTLN (payload); }}void Setup () {serial.begin (115200); int connectcount = 0; Wifi.begin (Ssid.c_str (), Password.c_str ()); while (Wifi.status ()! = wl_connected) {delay (1000); Serial.print ("."); if (Connectcount >) {serial.println ("Connect fail!"); Break } Connectcount + = 1; } if (wifi.status () = = wl_connected) {serial.println (""); Serial.print ("Connected to"); SERIAL.PRINTLN (SSID); Serial.print ("IP address:"); Serial.println (Wifi.locaLIP ()); Connectcount = 0; }//readyeelinkdata ("8938", "28887"); Read Data point test Uploadyeelinkdata ("8938", "28887", "1"); Write data point test} void Loop () {}
Arduino IDE for ESP8266 Tutorial (iii) HTTP client