带有MicroPython的Arduino ESP8266 Wifi连接

时间:2019-02-25 16:58:27

标签: python arduino arduino-esp8266 micropython

我已经购买了ESP8266并安装了micropython,但是当我尝试使用sta_if.connect(“ AP_name”,“ password”)连接到我的wifi并对其进行测试时,它始终为false。但是在我的路由器中有一个没有IP的实体。同样的问题是当我将Arduino IDE与c一起使用时。

它是ESP8266TelegramBOT.h的EchoBot,当我在Putty中干裂时,它只是在画点,因为它无法连接。当我在python中执行此操作时,它的模拟ist不连接。

#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h><
#include <ESP8266TelegramBOT.h>


// Initialize Wifi connection to the router
char ssid[] = "";              // your network SSID (name)
char password[] = "";                              // your network key



// Initialize Telegram BOT
#define BOTtoken ""  //token of TestBOT
#define BOTname "Door Bell"
#define BOTusername "Bell"
TelegramBOT bot(BOTtoken, BOTname, BOTusername);

int Bot_mtbs = 1000; //mean time between scan messages
long Bot_lasttime;   //last time messages' scan has been done

void Bot_EchoMessages() {

  for (int i = 1; i < bot.message[0][0].toInt() + 1; i++)      {
    bot.sendMessage(bot.message[i][4], bot.message[i][5], "");
  }
  bot.message[0][0] = "";   // All messages have been replied - reset new messages
}


void setup() {

  Serial.begin(115200);
  delay(3000);

  // attempt to connect to Wifi network:
  Serial.print("Connecting Wifi: ");
  Serial.println(ssid);
  while (WiFi.begin(ssid, password) != WL_CONNECTED) {
    Serial.print(".");
    //delay(500);
  }
  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  IPAddress ip = WiFi.localIP();
  Serial.println(ip);

  bot.begin();      // launch Bot functionalities
}

void loop() {

  if (millis() > Bot_lasttime + Bot_mtbs)  {
    bot.getUpdates(bot.message[0][1]);   // launch API GetUpdates up to xxx message
    Bot_EchoMessages();   // reply to message with Echo
    Bot_lasttime = millis();
  }
}

0 个答案:

没有答案