使用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:
  
}

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

相关推荐
lljss20207 天前
ESP8266+httpServer+GET+POST实现网页验证密码
esp8266
lljss20207 天前
ESP8266+eclipse+AP+最简单webserver
eclipse·esp8266
lljss20209 天前
ESP8266做httpServer提示Header fields are too long for server to interpret
esp8266
lljss202011 天前
win10+eclipse+ESP8266_RTOS_SDK开发环境构建
eclipse·esp8266
lljss202019 天前
ESP8266使用ESP8266_RTOS_SDK-3.4开发
esp8266
DijkstraPhoenix1 个月前
如何将Arduino当电脑用
arduino·硬件
吾名招财1 个月前
3-1 介绍及传感器(智能应用篇)
单片机·嵌入式硬件·arduino
吾名招财1 个月前
4-1-5 步进电机原理2(电机专项教程)
单片机·嵌入式硬件·arduino
吾名招财1 个月前
4-1-6 arduino控制42步进电机(电机专项教程)
单片机·嵌入式硬件·arduino