|
懇請教 Arduino使用 ESP8266 Wi-Fi上傳資料遭遇的問題
各位版上的前輩好,最近個人剛開始接觸Arduino
一直不斷想嘗試用手上的ESP8266 Wi-Fi晶片,將訊號資料上傳到雲端或自建的資料庫上作儲存統計
但無論反覆怎麼參考各種設定,都一直無法順利架動將數據上傳到thingspeak 或自機資料庫上頭
不知道各位否能由底下的資訊
指點出目前施作環結的問題癥結所在。#編譯環境為Linux 與Win皆有
底下是個人參考此網站的實驗流程:
http://ruten-proteus.blogspot.tw/2014/11/internet-of-thing-arduino-esp8266.html
目前測試的電路線路一
另一種方式是參考由書上教學的5V 降壓供電的線路
以下為測試的程式代碼
- #include <SoftwareSerial.h>
- #include "DHT.h"
- #define DEBUG
- #define _ledpin 13
- //*-- Hardware Serial
- #define _baudrate 9600
- //*-- Software Serial
- //
- #define _rxpin 2
- #define _txpin 3
- SoftwareSerial debug(_rxpin,_txpin); // RX, TX
- //*-- DHT11
- #define _dhtpin 8
- #define _dhttype DHT11
- DHT dht11( _dhtpin, _dhttype );
- uint8_t dhtbuf[2];
- //*-- IoT Information
- #define SSID "Tenda_5D1C08"
- #define PASS "12345678"
- #define IP "184.106.153.149" // ThingSpeak IP Address:api.thingspeak.com
- // GET /update?key=[THINGSPEAK_KEY]&field1=[data 1]&filed2=[data 2]...;
- String GET = "GET /update?key=0VD8RROGTK2MTIFT";
- void setup() {
- Serial.begin( _baudrate );
- debug.begin( _baudrate );
- sendDebug("AT");
- delay(5000);
- if(Serial.find("OK"))
- {
- debug.println("RECEIVED: OK\nData ready to sent!");
- connectWiFi();
- }
- // DHT11
- dht11.begin();
- pinMode( _ledpin, OUTPUT );
- digitalWrite( _ledpin, LOW );
- }
- void loop() {
- dhtbuf[0] = dht11.readHumidity();
- dhtbuf[1] = dht11.readTemperature();
- if( isnan(dhtbuf[0]) || isnan(dhtbuf[1]) )
- {
- debug.println( "Failed to read form DHT11" );
- }
- else
- {
- digitalWrite( _ledpin, HIGH );
- char buf[3];
- String HH, TT;
- buf[0] = 0x30 + dhtbuf[1] / 10;
- buf[1] = 0x30 + dhtbuf[1] % 10;
- TT = (String(buf)).substring( 0, 2 );
- buf[0] = 0x30 + dhtbuf[0] / 10;
- buf[1] = 0x30 + dhtbuf[0] % 10;
- HH = (String(buf)).substring( 0, 2 );
- updateDHT11( TT, HH );
- #ifdef DEBUG
- debug.print("Humidity: ");
- debug.print( HH );
- debug.print(" %\t");
- debug.print("Temperature: ");
- debug.print( TT );
- debug.println(" *C\t");
- #endif
- digitalWrite( _ledpin, LOW );
- }
- delay(6000); // 6second
- }
- void updateDHT11( String T, String H )
- {
- // ³]©w ESP8266 §@¬° Client ºÝ
- String cmd = "AT+CIPSTART=\"TCP\",\"";
- cmd += IP;
- cmd += "\",80";
- sendDebug(cmd);
- delay(2000);
- if( Serial.find( "Error" ) )
- {
- debug.print( "RECEIVED: Error\nExit1" );
- return;
- }
- cmd = GET + "&field1=" + T + "&field2=" + H +"\r\n";
- Serial.print( "AT+CIPSEND=" );
- Serial.println( cmd.length() );
- if(Serial.find( ">" ) )
- {
- debug.print(">");
- debug.print(cmd);
- Serial.print(cmd);
- }
- else
- {
- sendDebug( "AT+CIPCLOSE" );
- }
- if( Serial.find("OK") )
- {
- debug.println( "RECEIVED: OK" );
- }
- else
- {
- debug.println( "RECEIVED: Error\nExit2" );
- }
- }
- void sendDebug(String cmd)
- {
- debug.print("SEND: ");
- debug.println(cmd);
- Serial.println(cmd);
- }
- boolean connectWiFi()
- {
- Serial.println("AT+CWMODE=1");
- delay(2000);
- String cmd="AT+CWJAP=\"";
- cmd+=SSID;
- cmd+="\",\"";
- cmd+=PASS;
- cmd+="\"";
- sendDebug(cmd);
- delay(5000);
- if(Serial.find("OK"))
- {
- debug.println("RECEIVED: OK");
- return true;
- }
- else
- {
- debug.println("RECEIVED: Error");
- return false;
- }
- cmd = "AT+CIPMUX=0";
- sendDebug( cmd );
- if( Serial.find( "Error") )
- {
- debug.print( "RECEIVED: Error" );
- return false;
- }
- }
複製代碼
序列埠監控視窗的訊息
之前版上有版友也提問過類似的問題
但參考其作法 將TX RX 改接 0和1 問題依舊無解
http://www.robofun.net/forum/thread-10017-1-2.html |
|