当前位置:网站首页>Esp8266 nodemcu - get real-time weather from Suning API
Esp8266 nodemcu - get real-time weather from Suning API
2022-07-23 23:21:00 【Embedded maker workshop】
Preface
This article introduces how to use ESP8266-NodeMCU From Suning API Get real-time weather , Suning API: Click the jump
It is shown below :

What we want to capture is the content of the red line , And print through serial port . Of course , This part can also be used to display in OLED On , That's how I used to play .
Before the official start , Need to know how to use WiFiManager Library connection wifi The process of , In the code below wifi Connection used WiFiManager library , There is nothing to connect wifi The name and password are written directly into the code , Specific operations can jump to reference : ESP8266-NodeMCU—— Use WiFiManager Library connection wifi
One 、 Software preparation
(1)Arduino IDE
Two 、 Hardware preparation
(1)ESP8266-NodeMCU

(2) One that can transmit data micro USB Line

3、 ... and 、 Implementation code
#include <WiFiManager.h>
#include <ESP8266HTTPClient.h>
#include <ArduinoJson.h>
char Json_Time[36]; // From Suning API Acquired Json data ( After parsing ) Array of
const String timeUrl = "http://quan.suning.com/getSysTime.do"; // Suning API Address
String timeMsg=""; // Grab the time part
String timeAfterParse=" "; //Json Parsed valid data cache string
char flag;
String callHttp(String httpUrl); // Capture time website Json data
String parseJsonTime(String tjson); // analysis Json data
void setup()
{
Serial.begin(115200); // Serial port baud rate is set to 115200
connectWifi(); // Connect WiFi, Only after connecting will it continue to run
}
void loop()
{
timeMsg = callHttp(timeUrl); // obtain JSon data
if(timeMsg!="" ) // If the data is successfully obtained
{
timeAfterParse = parseJsonTime(timeMsg); // analysis Json data
timeAfterParse.toCharArray(Json_Time,timeAfterParse.length() + 1); //Json_Time Will become an array of strings , Content and timeAfterParse equally
Serial.println(Json_Time);
}
delay(900);
}
//================================================ Connect WiFi==================================================================
void connectWifi(){
WiFiManager wifiManager;
wifiManager.autoConnect("ESP8266-NodeMCU");
}
//================================================= analysis Json The data is a string =====================================================
String parseJsonTime(String tjson){
const size_t capacity =96;
DynamicJsonDocument tdoc(capacity);
deserializeJson(tdoc, tjson); // Deserialized data
String datetime = tdoc["sysTime2"].as<String>(); // Get the parsed data information
return datetime;
}
//================================================= Capture time website Json data =====================================================
String callHttp(String httpUrl) {
HTTPClient hClient;
String message;
hClient.begin(httpUrl); // Connect API Address
int httpCode = hClient.GET(); // The request for Json data
if (httpCode > 0) {
if (httpCode == HTTP_CODE_OK) {
String payload = hClient.getString(); // Data transfer
message = payload;
}
} else {
message = "[1-HTTP]failed, error:" + String(hClient.errorToString(httpCode).c_str()); // If the acquisition fails, an error will be reported
}
hClient.end(); // close API
return message; // Return information
}
Four 、 Realization effect

If the network is not good, the effect may not be so ideal , You may not be able to crawl every second , But when I was testing , Seems to be API The interface itself is a card , Sometimes when you open it with a computer, it also shows timeout , I used to play very smoothly
边栏推荐
- Three network modes of VMware virtual machine
- Tensorflow one layer neural network training handwritten digit recognition
- [in depth study of 4g/5g/6g topic -40]: urllc-11 - in depth interpretation of 3GPP urllc related protocols, specifications and technical principles -5-5g QoS principle and Architecture: slicing, PDU s
- A great open source micro community light forum source code
- Mobile, telecom and Unicom: fancy solution of 5g to B
- FreeRTOS personal notes - delay function
- ES6箭头函数的使用
- 1000个Okaleido Tiger首发上线Binance NFT,引发抢购热潮
- 疑似未系安全带 林志颖伤势相对稳定
- Software architecture
猜你喜欢

USB转CAN设备在核酸提取仪 高性能USB接口CAN卡

Entropy weight method to optimize TOPSIS (matlab)

Smart IOT source code with configuration IOT source code industrial IOT source code: support sensor analysis services, real-time data collection and remote control

dried food! Implicit sparse regularization effect in neural networks

Preparation for raspberry pie 3B serial port login

AutoCAD advanced operation

Software architecture

TAP 系列文章7 | 易于管理的流水线配置

TAP 系列文章8 | TAP 学习中心——通过动手教程来学习

This article will show you what typescript is
随机推荐
[tensorflow] check whether tensorflow GPU is available
Basic operations of AutoCAD
Debian | Can’t locate Debian/Debhelper/Sequence/germinate. pm in @INC
ES6 use of arrow function
BGP routing, MPLS
Rosbag file recorded by LIDAR point cloud data is converted into CSV file
Sword finger offer II 115. reconstruction sequence
fl studio 20.9更新中文版宿主DAW数字音频工作站
D2admin framework is basically used
[web vulnerability exploration] SQL injection vulnerability
1000 okaleido tiger launched binance NFT, triggering a rush to buy
Chinese NFT? NFR was born
Tap series article 8 | tap Learning Center - learn through hands-on tutorials
How to reasonably estimate the size of thread pool
ArraysList 与顺序表 ——模拟实现
Interface test
Lu Xia action | Source Kai Digital: Existing Mode or open source innovation?
AutoCAD advanced operation
BGP基础实验
2022-7-22 face review + simple topic sorting