大家好
我想請問 關於 ESP-WROOM-02 連不到WIFI了話 哪裡有問題??
以下為我的程式 和線路圖
#include "ESP8266.h"
#include "Milkcocoa.h"
#include "Client_ESP8266.h"
// 傳輸率
#define SERIAL_SPEED 115200
/************************* WiFi Access Point *********************************/
// Wi-Fi SSID
#define WLAN_SSID "pcsetting-wifitest"
// Wi-Fi PASSWORD
#define WLAN_PASS "jetproinc"
// Milkcocoa的APP ID
#define MILKCOCOA_APP_ID "onj3v4c9jn"
// Data Store名稱
#define MILKCOCOA_DATASTORE "sensor"
#define MILKCOCOA_SERVERPORT 1883
// Create an ESP8266Client class to connect to the MQTT server.
ESP8266Client wifi;
const char MQTT_SERVER[] PROGMEM = MILKCOCOA_APP_ID ".mlkcca.com";
const char MQTT_CLIENTID[] PROGMEM = __TIME__ MILKCOCOA_APP_ID;
Milkcocoa milkcocoa = Milkcocoa(&wifi, MQTT_SERVER, MILKCOCOA_SERVERPORT, MILKCOCOA_APP_ID, MQTT_CLIENTID);
// 跟感測器接在一起的腳
const int sensorPin = A0;
void setup() {
// 開啟跟電腦之間序列通信的埠
Serial.begin(SERIAL_SPEED);
// 開啟跟Wi-Fi模組之間序列通信的埠
Serial5.begin(SERIAL_SPEED);
// Wi-Fi設定
setupWiFi();
}
/*
設定Wi-Fi
*/
void setupWiFi() {
Serial.print("Connecting to ");
Serial.println(WLAN_SSID);
// 指定序列埠
wifi.begin(Serial5);
// 連接Wi-Fi(重複處理直到連接成功)
while (!wifi.joinAP(WLAN_SSID, WLAN_PASS)) {
delay(500);
Serial.print(".*.");
}
Serial.println("Wi-Fi connected");
Serial.println("IP address: ");
// 把Wi-Fi的local IP位置顯示在序列埠監控視窗上
Serial.println(wifi.getLocalIP().c_str());
}
void loop() {
// 執行Milkcocoa的loop處理
milkcocoa.loop();
// 感測器的值
int sensorValue = analogRead(sensorPin);
Serial.print("Sensor Value : ");
Serial.println(sensorValue);
// 做成傳送給Milkcocoa的資料
DataElement elem = DataElement();
// 以sensorValue這個資料名稱來追加值
elem.setValue("sensorValue", sensorValue);
// 送資料到Milkcocoa
milkcocoa.send(MILKCOCOA_DATASTORE, &elem);
}
|