使用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 天前
基于Arduino模拟烟雾监测系统
单片机·嵌入式硬件·arduino
EleganceJiaBao14 天前
【ESP8266】使用 ESP8266 + CoolTerm + Packet Sender 构建 TCP 通信的完整调试流程
网络协议·tcp/ip·wi-fi·esp8266·coolterm·packet sender
2401_8534482315 天前
FreeRTOS项目---WiFi模块(2)
stm32·单片机·freertos·esp8266·通信协议
文sir.19 天前
温湿度采集系统(stm32+mqtt+Onenet云平台+esp8266)
stm32·单片机·嵌入式硬件·mqtt·onenet·云平台·esp8266
2401_8534482320 天前
ESP8266蓝牙模块
stm32·蓝牙模块·esp8266
刻BITTER21 天前
用EXCEL 将单色屏幕的Bitmap 字模数据还原回图形
单片机·嵌入式硬件·excel·arduino
kaka❷❷1 个月前
STM32 单片机 ESP8266 联网 和 MQTT协议
stm32·单片机·嵌入式硬件·物联网·mqtt·esp8266
MAO_JIN_DAO2 个月前
ESP3266 NodeMCU 使用Arduino点亮 ST7789 240x240 tft屏
arduino·esp8266·tft·st7789
刻BITTER2 个月前
用CMake 实现U8g2 的 SDL2 模拟环境
c++·stm32·单片机·嵌入式硬件·arduino
jianqiang.xue2 个月前
单片机图形化编程:课程目录介绍 总纲
c++·人工智能·python·单片机·物联网·青少年编程·arduino