更新 Sketch1.ino

新增注释
This commit is contained in:
JasonYANG17 2023-09-04 09:13:21 +08:00 committed by GitHub
parent 3783180162
commit 1fad5021c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

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