mirror of
https://github.com/JasonYANG170/YANG-SSD.git
synced 2024-11-23 03:56:33 +00:00
更新 Sketch1.ino
新增注释
This commit is contained in:
parent
3783180162
commit
1fad5021c9
|
@ -1,8 +1,9 @@
|
|||
/*
|
||||
Name: YANG SSD OS.ino
|
||||
Created: 2023/5/3 19:24:00
|
||||
Author: qw200
|
||||
Author: JasonYANG17
|
||||
*/
|
||||
//导入所需库
|
||||
#include <SPI.h>
|
||||
#include <Wire.h>
|
||||
#include <Adafruit_GFX.h>
|
||||
|
@ -13,17 +14,19 @@
|
|||
#include <WiFiClientSecure.h>
|
||||
#include <ArduinoJson.h>
|
||||
#include <WiFiManager.h>
|
||||
|
||||
//配置像素及颜色
|
||||
Adafruit_SH1106G display = Adafruit_SH1106G(128, 64, &Wire);
|
||||
|
||||
//配置AHT驱动
|
||||
Adafruit_AHTX0 aht;
|
||||
|
||||
void setup() {
|
||||
//配置串口调试频率
|
||||
Serial.begin(115200);
|
||||
//while (!Serial);
|
||||
|
||||
|
||||
Serial.println("128x64 OLED FeatherWing test");
|
||||
//配置iic地址
|
||||
display.begin(0x3C, true); // Address 0x3C default
|
||||
|
||||
Serial.println("OLED begun");
|
||||
|
@ -34,21 +37,24 @@ void setup() {
|
|||
|
||||
|
||||
// Clear the buffer.
|
||||
//清屏
|
||||
display.clearDisplay();
|
||||
|
||||
|
||||
//设置光标位置(屏幕坐标点)
|
||||
display.setRotation(0);
|
||||
|
||||
//检查AHT20是否工作
|
||||
if (aht.begin()) {
|
||||
Serial.println("Found AHT20");
|
||||
} else {
|
||||
Serial.println("Didn't find AHT20");
|
||||
}
|
||||
|
||||
//配置文本大小
|
||||
display.setTextSize(5);
|
||||
//配置颜色
|
||||
display.setTextColor(SH110X_WHITE);
|
||||
//配置输出文本
|
||||
display.print("YANG ");
|
||||
|
||||
//显示输出
|
||||
display.display();
|
||||
|
||||
display.setTextSize(2);
|
||||
|
@ -62,17 +68,19 @@ void setup() {
|
|||
display.print("Connecting to WiFi...");
|
||||
|
||||
display.display();
|
||||
WiFi.mode(WIFI_STA); // 设置模式,esp默认为STA+AP
|
||||
WiFiManager wm; //定义manager对象
|
||||
//配置wifi模式
|
||||
WiFi.mode(WIFI_STA); // 设置模式,esp默认为STA+AP
|
||||
//定义对象
|
||||
WiFiManager wm; //定义manager对象
|
||||
bool res;
|
||||
res = wm.autoConnect("Flowerpot","12345678"); //定义ap名称和密码
|
||||
res = wm.autoConnect("Flowerpot","12345678"); //定义ap名称和密码(bool型)
|
||||
|
||||
|
||||
display.setTextSize(1);
|
||||
}
|
||||
String asdsd;
|
||||
void loop() {
|
||||
net("https://api.vvhan.com/api/en?type=sj");
|
||||
net("https://api.vvhan.com/api/en?type=sj");//调用webapi函数
|
||||
delay(5000);
|
||||
display.clearDisplay();
|
||||
display.setRotation(0);
|
||||
|
@ -90,32 +98,33 @@ delay(5000);
|
|||
display.println(asdsd);
|
||||
display.display();
|
||||
}
|
||||
//webapi函数
|
||||
void net(String url) {
|
||||
if (WiFi.status() == WL_CONNECTED) {
|
||||
WiFiClientSecure client;
|
||||
client.setInsecure(); // Do not verify certificate
|
||||
HTTPClient https;
|
||||
https.begin(client, url);
|
||||
int httpCode = https.GET();
|
||||
if (httpCode > 0) {
|
||||
String payload = https.getString();
|
||||
Serial.println(payload);
|
||||
if (WiFi.status() == WL_CONNECTED) {//确认网络是否连接
|
||||
WiFiClientSecure client;//配置网络客户机
|
||||
client.setInsecure(); // Do not verify certificate配置为不安全的网络认证
|
||||
HTTPClient https;//配置为Https代理
|
||||
https.begin(client, url);//发送客户机和URL请求
|
||||
int httpCode = https.GET();//获取HttpGet请求返回值
|
||||
if (httpCode > 0) {//返回值大于0代表请求成功
|
||||
String payload = https.getString();//获取Get请求返回文本
|
||||
Serial.println(payload);/输出返回文本
|
||||
Serial.println("");
|
||||
// 重点1:即将解析的json文件
|
||||
// 重点1:即将解析的json文件
|
||||
String json = payload;
|
||||
Serial.println(String("") + "JSON大小:" + json.length());
|
||||
// 重点2:解析的JSON数据大小
|
||||
DynamicJsonDocument doc(json.length() * 2); //解析的JSON数据大小
|
||||
Serial.println(String("") + "JSON大小:" + json.length());
|
||||
// 重点2:解析的JSON数据大小
|
||||
DynamicJsonDocument doc(json.length() * 2); //解析的JSON数据大小
|
||||
|
||||
|
||||
// 重点3:反序列化数据
|
||||
// 重点3:反序列化数据
|
||||
deserializeJson(doc, json);
|
||||
|
||||
// 重点4:获取解析后的数据信息
|
||||
// 重点4:获取解析后的数据信息
|
||||
String nameStr = doc["data"]["en"].as<String>();
|
||||
// int numberInt = doc["time"].as<int>();
|
||||
asdsd = nameStr;
|
||||
// 通过串口监视器输出解析后的数据信息
|
||||
// 通过串口监视器输出解析后的数据信息
|
||||
Serial.print("errorStr = "); Serial.println(nameStr);
|
||||
//Serial.print("errnoInt = ");Serial.println(numberInt);
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user