I am sending data from an ESP8266 to an Uno (I need to use the Uno because it has more inputs than the ESP and I need those for my project.) The ESP8266 is connected to the Uno's Serial pins 0/1 RX/TX (communicating on BAUD rate of 9600), and then I have a SoftwareSerial out from the Uno (on a BAUD rate of 57600) for debugging. Something weird is happening though. The transfer works a couple times and then I get this in the log:
--------------- CUT HERE FOR EXCEPTION DECODER ---------------
Exception (0):
epc1=0x40239ba1 epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000000 depc=0x00000000
>>>stack>>>
ctx: sys
sp: 3fffebd0 end: 3fffffb0 offset: 0190
3fffed60: 40239b2e 3feffe00 3fffd9d0 00000050
3fffed70: 000005e0 00000000 40103501 3ffed4d0
3fffed80: 0000003c 00000000 00000022 401049e6
3fffed90: 401049c8 3fffc100 3ffef2a0 00000000
3fffeda0: 00000000 4022279f 00000020 40100198
3fffedb0: 400005e1 150cc636 00000005 4010144c
3fffedc0: 4022279f 00000030 00000010 3ffefdcc
3fffedd0: 40221007 3fff051a 00000014 00000000
3fffede0: 00000000 00000061 00000061 00000001
3fffedf0: 3ffecdb8 00000006 00000000 3fff04fc
3fffee00: 3fff051a 3ffef2a0 00000061 00000000
3fffee10: 3ffe9be8 7fffffff 50800000 00000001
3fffee20: 00000001 00004a08 00000142 401006d7
Any ideas what could be causing this? Here is the code that the Uno uses for receiving from the ESP and printing to the SoftwareSerial (Serial is the RX/TX and mySerial is the SoftwareSerial). It uses a couple helper functions I haven't included here but let me know if you need them:
void receiveFromESP() {
if (Serial.available() > 0 ) {
endofTransmission == 0;
alreadyZeroed = 0 ;
receivedChar = Serial.read();
mySerial.print(receivedChar);
if (receivedChar == '[' ) {
lastNum = 0 ;
commaNumber = 0 ;
lastWasNum = 0 ;
}
if (receivedChar == '*' ) {
lastNum = 0 ;
commaNumber = 0 ;
lastWasNum = 0 ;
createArray[0] = 4;
createArray[1] = 4;
createArray[2] = 4;
createArray[3] = 4;
}
if (receivedChar == 'A'
|| receivedChar == 'B'
|| receivedChar == 'C'
|| receivedChar == 'D'
|| receivedChar == 'E'
|| receivedChar == 'F'
|| receivedChar == 'G'
|| receivedChar == 'H'
|| receivedChar == 'I'
|| receivedChar == 'J'
|| receivedChar == ','
) {
if (lastWasNum == 1) {
createArray[commaNumber] = lastNum;
commaNumber++;
}
lastWasNum = 0 ;
createArray[commaNumber] = charToNumber(receivedChar);
commaNumber++;
lastNum = 0 ;
}
if (receivedChar == ']') {
lastWasNum = 0 ;
endofTransmission = 1 ;
for (int i = 0; i < 50; i++) {
mySerial.print(createArray[i]);
mySerial.print(':');
}
}
if (
receivedChar == '0'
|| receivedChar == '1'
|| receivedChar == '2'
|| receivedChar == '3'
|| receivedChar == '4'
|| receivedChar == '5'
|| receivedChar == '6'
|| receivedChar == '7'
|| receivedChar == '8'
|| receivedChar == '9'
) {
lastWasNum = 1;
receivedCharInt = (int)receivedChar - 48;
lastNum = lastNum * 10 + receivedCharInt;
}
t = millis();
}
};
As requested, here is the full ESP code:
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>
#include <ESP8266HTTPClient.h>
#include <WiFiClient.h>
#include <DNSServer.h> //Local DNS Server used for redirecting all requests to the configuration portal
#include <ESP8266WebServer.h> //Local WebServer used to serve the configuration portal
#include <WiFiManager.h> //https://github.com/tzapu/WiFiManager WiFi Configuration Magic
#define SERIAL_BUFFER_SIZE 256
void setup() {
Serial.begin(9600);
for (uint8_t t = 4; t > 0; t--) {
Serial.printf("*WIFISETUP] WAIT %d...\n", t);
Serial.flush();
delay(1000);
}
WiFiManager wifiManager;
wifiManager.setConfigPortalTimeout(120);
//first parameter is name of access point, second is the password
wifiManager.autoConnect("AP-NAME", "AP-PASSWORD");
}
void loop() {
WiFiClient client;
HTTPClient http;
if (http.begin(client, "[URL]")) { // HTTP
// start connection and send HTTP header
http.addHeader("Content-Type", "text/plain");
http.addHeader("Authorization", "Basic dXNlcm5hbWU6cGFzc3dvcmQ=");
int httpCode = http.GET();
if (httpCode == 200 ) { // HTTP header has been sent and Server response header has been handled
// file found at server
if (httpCode == HTTP_CODE_OK || httpCode == HTTP_CODE_MOVED_PERMANENTLY) {
String payload = http.getString();
Serial.println(payload);
}
} else{
if (httpCode > 0 ){
//website problem
Serial.printf("[2,1,1,1]");
}
if (httpCode == -1 ){
//wifi problem
Serial.printf("[4,1,1,1]");
ESP.reset();
}
}
http.end();
} else {
Serial.printf("[HTTP} Unable to connect\n");
}
delay(10000);
}
if (receivedChar >= '0' && receivedChar <='9')
would be much simpler for your Arduino code.