使用arduino编程在基于esp8266的nodemcu开发板上实现开机自动连接wifi

一、简介

准备用基于esp8266的nodemcu开发板做一个天气时钟。目前只实现了第一阶段任务的第一点要求。使用arduino编程,在基于esp8266的nodemcu开发板上实现开机自动连接wifi。

这里做个记录。

二、我目前在使用的云服务器推荐

学Linux不搞个云服务器始终感觉不爽!

要稳定性、安全性、不差钱的可以使用阿里、腾讯等大厂的云服务器。

本人穷屌丝一枚,所以我用的是免费的"三丰云",同时提供"免费虚拟主机"和"免费云服务器"产品,有兴趣的可以试一下。

"三丰云"我已经用了一段时间,感觉还是很不错的,速度快也很稳定。

三丰云 https://www.sanfengyun.com 链接。

大家可以点击前往查看是否需要。

三、程序代码如下
cpp 复制代码
/*
  竹壳天气时钟
  Bamboo shell weather clock

  使用基于esp8266的NodeMCU制作。
  计划用竹子做最后成品的外壳,所以才有了这个名称。

  第一阶段任务:
  1、实现WiFi连接;
  2、如果30秒后还没连接成功就开启混合模式,
     使用webserver进行设置,
     手动扫描并连接WiFi。
     2024年9月19日开始
*/
#include <ESP8266WiFi.h>

#ifndef STASSID
#define STASSID "your-ssid"
#define STAPSK "your-password"
#endif

const char* ssid = STASSID;
const char* password = STAPSK;

void setup() {
  // put your setup code here, to run once:
  // 打印信息
  Serial.begin(115200);
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);
  // 连接WiFi
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);
  // 连接过程中打印出读秒的数字
  int i=0;
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print(i);
    i++;
    if (i > 30) {
      
      return;
    }
    delay(1000);
  }
  // 连接成功后打印消息和本地IP
  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
}

void loop() {
  // put your main code here, to run repeatedly:
  
}

我还在学习摸索中,如有问题请评论区留言,我会测试修复。非常感谢!

相关推荐
胖多鱼6 天前
WeMos D1+PIR+Android 的小场景制作
android·arduino·pir·hc-sr501
极梦网络无忧9 天前
Arduino 第十六章:pir红外人体传感器练习
单片机·嵌入式硬件·arduino
生活最重要(ง •̀_•́)ง13 天前
[ESP32:Vscode+PlatformIO]添加第三方库 开源库 与Arduino导入第三方库的区别
esp32·arduino·第三方库·开源库·platformio
冰羽IOX17 天前
CH340G上传程序到ESP8266-01(S)模块
arduino·esp8266·ch340g·usb to ttl
生活最重要(ง •̀_•́)ง20 天前
[ESP32:Vscode+PlatformIO]新建工程 常用配置与设置
vscode·esp32·arduino·platformio
抠脚学代码1 个月前
ESP8266 MQTT服务器+阿里云
mqtt·阿里云·esp8266
Grayson_Zheng1 个月前
如何用 ESP32-CAM 做一个实时视频流服务器
esp32·arduino·camera·电子信息
无敌海苔咪1 个月前
VsCode对Arduino的开发配置
ide·vscode·编辑器·arduino
xachary2 个月前
Arduino 小白的 DIY 空气质量检测仪(5)- OLED显示模块、按钮模块
物联网·嵌入式·arduino
_古_凡_2 个月前
【LVGL】给SquareLineStudio导出的Arduino工程添加物理按键
单片机·arduino·lvgl·esp8266