我正试图让post 8266-01与我的DHT11传感器一起工作,并将数据发布到Thingspeak。
为了将我的代码上传到ESP8266,我使用了带有FTDI232模型的TTL到USB,并选择了3.3v的输出。
在第一次尝试中,我能够上传esp示例中的“眨眼”示例,然后尝试用传感器上传我的代码,但是没有成功,在上传草图时得到了错误信息。
我试图上传的代码如下:
// www.arduinesp.com
//
// Plot DTH11 data on thingspeak.com using an ESP8266
// April 11 2015
// Author: Jeroen Beemster
// Website: www.arduinesp.com
#include <DHT.h>
#include <ESP8266WiFi.h>
// replace with your channel’s thingspeak API key,
String apiKey = "EQE7GT28UMUW17CH";
const char* ssid = "GC-Office-WLAN1";
const char* password = "bsontkgcmxitwn30of01101911";
const char* server = "api.thingspeak.com";
#define DHTPIN 2 // what pin we’re connected to
DHT dht(DHTPIN, DHT11,15);
WiFiClient client;
void setup() {
Serial.begin(115200);
delay(10);
dht.begin();
WiFi.begin(ssid, password);
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
}
void loop() {
float h = dht.readHumidity();
float t = dht.readTemperature();
if (isnan(h) || isnan(t)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
if (client.connect(server,80)) { // "184.106.153.149" or api.thingspeak.com
String postStr = apiKey;
postStr +="&field1=";
postStr += String(t);
postStr +="&field2=";
postStr += String(h);
postStr += "\r\n\r\n";
client.print("POST /update HTTP/1.1\n");
client.print("Host: api.thingspeak.com\n");
client.print("Connection: close\n");
client.print("X-THINGSPEAKAPIKEY: "+apiKey+"\n");
client.print("Content-Type: application/x-www-form-urlencoded\n");
client.print("Content-Length: ");
client.print(postStr.length());
client.print("\n\n");
client.print(postStr);
Serial.print("Temperature: ");
Serial.print(t);
Serial.print(" degrees Celcius Humidity: ");
Serial.print(h);
Serial.println("% send to Thingspeak");
}
client.stop();
Serial.println("Waiting…");
// thingspeak needs minimum 15 sec delay between updates
delay(60000);
}
我得到的错误消息如下:
Arduino:1.6.12 (Windows 7), Tarjeta:"Generic ESP8266 Module, 80 MHz, 40MHz, DIO, 512000, 512K (64K SPIFFS), ck, Disabled, None"
El Sketch usa 233,113 bytes (53%) del espacio de almacenamiento de programa. El máximo es 434,160 bytes.
Las variables Globales usan 32,432 bytes (39%) de la memoria dinámica, dejando 49,488 bytes para las variables locales. El máximo es 81,920 bytes.
Uploading 237264 bytes from C:\Users\nmnerzul\AppData\Local\Temp\arduino_build_881344/humedadesp8266solo.ino.bin to flash at 0x00000000
..........warning: espcomm_send_command: didn't receive command response
warning: espcomm_send_command(FLASH_DOWNLOAD_DATA) failed
warning: espcomm_send_command: wrong direction/command: 0x01 0x03, expected 0x01 0x04
error: espcomm_upload_mem failed
error: espcomm_upload_mem failed
我用的是带有1A的3.3外部电源。我把它连接起来为ESP8266模块供电。
我在Arduino IDE中的设置如下。
我尝试了以下几点:
更新前重置模块,改变闪存大小(在512 K时改变为1M ),改变速度(测试512000,9600,115200),我只能上传这个眨眼示例。
希望这些信息足够了。耽误您时间,实在对不起。
发布于 2018-06-06 04:27:30
这个问题实际上与代码无关。这无疑是硬件连接/数据同步的问题。
在尝试我的解决方案时,请尽量不要破坏软件。采用推荐的115200上传速度和,如果ESP的PCB是黑色的,则模块更有可能是1M而不是512个闪存大小(但是闪存大小不应该在这里测量)。
因此,我无法清楚地看到USBtoTTL和ESP01之间的连接,因此请检查您的连接是否与完全相同,如下:
╭────────────┬─────────────╮
│ ESP01 │ USBtoTTL │
╞════════════╪═════════════╡
│ RX │ TX │
│ TX │ RX │
│ VCC │ VCC │
│ CH_PD │ VCC │
│ GND │ GND │
│ GPIO0 │ GND │
└────────────┴─────────────┘
这样,当你打开你的电除尘器,你应该看到只有一眨眼的嵌入式蓝光LED,这意味着模块是现在在闪存模式。
尝试在ARDUINO IDE中单击UPLOAD按钮,就在之后--您看到这一次眨眼
如果此步骤对您有效,请检查您的电源GND是否与USBtoTTL和您的ESP.相同。
最后,也是最不幸的原因是,之间的连线/连接质量很差。I已经与几种类型的ESP模块合作了一年多了,有时上传时仍有一些失败。您所能做的就是尝试不同的USB电缆,并减少连接在面包板上的数量。我建议购买/DIY一个USBtoTTL->ESP01 01适配器固体原型板与短焊丝。
如果这不会有帮助,请向我提供信息,如果这是您唯一的错误类型,或者它可能已经失败,有时上传或其他什么。
https://stackoverflow.com/questions/41912930
复制相似问题