esp8266 / Arduino

ESP8266 core for Arduino
GNU Lesser General Public License v2.1
16.09k stars 13.33k forks source link

ESP8266 12F have to jump TXD RXD to run well #4865

Closed MMKC closed 6 years ago

MMKC commented 6 years ago

I found a problem about RXD TXD ( UART0) of ESP12F If I don't connect RXD TXD => ESP doesn't run stable If I jump RXD with TXD => ESP run well If I connect RXD (ESP12F) -> TXD ( UASB adapter UART ) TXD (ESP12F) -> RXD ( UASB adapter UART )
ESP12 runs well

I think problem is about UART0 In code, I turn off UART0

`#include

include

const char ssid = "MMKC"; const char password = "@khongbiet@"; /*#define ORG "9wk14d" // "quickstart" or use your organisation

define DEVICE_ID "ServerESP"

define DEVICE_TYPE "esp8266" // your device type or not used for "quickstart"

define TOKEN "12345678" // your device token or not used for "quickstart"*/

define publish_topic "mmkc/sensor_2/send_value"

define subcribe_topic "mmkc/sensor_2/get_value"

define brk_status "/status"

define brk_value "/value"

define brk_reset "/reset"

//-------- Customise the above values --------

//char server[] = ORG ".messaging.internetofthings.ibmcloud.com"; char server[] = "test.mosquitto.org"; //char topic[] = "iot-2/evt/status/fmt/json"; char publish_topic_status[] = publish_topic brk_status; char publish_topic_value[] = publish_topic brk_value; char publish_topic_reset[] = publish_topic brk_reset;

/char authMethod[] = "use-token-auth"; char token[] = TOKEN; char clientId[] = "d:" ORG ":" DEVICE_TYPE ":" DEVICE_ID;/ char msg[50]; int sd_status,sd_value,sd_reset; long lastMsg = 0; WiFiClient espClient2; PubSubClient client(server, 1883, espClient2);

void setup() { pinMode(5,OUTPUT); pinMode(4,OUTPUT); // Serial.begin(115200); setup_wifi(); client.setServer(server, 1883); client.setCallback(callback); reconnect(); }

void setup_wifi(){

delay(10); // We start by connecting to a WiFi network // 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"); // Serial.println("IP address: "); // Serial.println(WiFi.localIP()); }

void callback(char topic, byte payload, unsigned int length) { // Serial.print("Message arrived ["); // Serial.print(topic); // Serial.print("] "); for (int i = 0; i < length; i++) { // Serial.print((char)payload[i]); }

if((char)payload[0] == 'o' && (char)payload[1] == 'n') //on digitalWrite(4,HIGH); else if((char)payload[0] == 'o' && (char)payload[1] == 'f' && (char)payload[2] == 'f') //off digitalWrite(4,LOW);
// Serial.println(); }

void reconnect() { // Loop until we're reconnected while (!client.connected()) {
// Serial.print("Attempting MQTT connection..."); // Attempt to connect if (client.connect("ESP8266Clientvn33")) { // Serial.println("connected"); // Once connected, publish an announcement... // client.publish("mmkc/sensor_2/send_value", "Connected!"); // ... and resubscribe // client.subscribe("mmkc/sensor_2/get_value"); } else { // Serial.print("failed, rc="); // Serial.print(client.state()); // Serial.println(" try again in 5 seconds"); // Wait 5 seconds before retrying delay(5000); } } }

void loop() { if (!client.connected()) { reconnect(); }

client.loop();

long now = millis(); if (now - lastMsg > 2000) { lastMsg = now; ++sd_value; snprintf (msg, 75, "#%d %", sd_value); // Serial.print("Publish: "); // Serial.print(publish_topic_value); // Serial.print(" : "); // Serial.println(msg); client.publish(publish_topic_value, msg);

snprintf (msg, 75, "#%d", sd_status); // Serial.print("Publish: "); // Serial.print(publish_topic_status); // Serial.print(" : "); // Serial.println(msg); client.publish( publish_topic_status, msg);

snprintf (msg, 75, "#%d", sd_reset); // Serial.print("Publish : "); // Serial.print(publish_topic_reset); // Serial.print(" : "); // Serial.println(msg); client.publish( publish_topic_reset, msg); if (sd_value >=50) sd_value=0; //if (sd_value >=45) } }`

RudyFiero commented 6 years ago

Connect a pull up resistor to RX. Make sure you give it a high (idle state) that it expects.

Or set the pin as an input with internal pull-up. But I think the problem is earlier than that stage.

I don't think this is a result of the Arduino code here. I think it related to the Expressif boot code. For me, it was never worth looking into.

devyte commented 6 years ago

Previous comment is correct, this sounds like a hw issue. The hw uart has been stress-tested, and there are no known issues at this time. The only pending is a PR with some minor optimizations. Closing.