Hi,
This is part of the code I am trying to port on an ESP8266:
#include <Arduino.h>
#define BUFFER_SIZE 256 ///< Set the size of serial buffer
#define BAUDRATE 9600 ///< Set the Baudrate of easycomm 3 protocol
void setup() {
Serial.begin(BAUDRATE);
}
void loop() {
char buffer[BUFFER_SIZE];
char incomingByte;
char *Data = buffer;
char *rawData;
static uint16_t BufferCnt = 0;
char data[100];
// Read from serial
while (Serial.available() > 0) {
ESP.wdtFeed();
incomingByte = Serial.read();
// Read new data
if (incomingByte == '\n' || incomingByte == '\r') {
buffer[BufferCnt] = 0;
if (buffer[0] == 'A' && buffer[1] == 'Z') {
if (buffer[2] == ' ' && buffer[3] == 'E' && buffer[4] == 'L') {
Serial.println("Dummy");
} else {
rawData = strtok_r(Data, " ", &Data);
strncpy(data, rawData + 2, 10);
if (isNumber(data)) {
Serial.print("AZ: ");
Serial.println(atof(data));
}
rawData = strtok_r(Data, " ", &Data);
if (rawData[0] == 'E' && rawData[1] == 'L') {
strncpy(data, rawData + 2, 10);
if (isNumber(data)) {
Serial.print("EL: ");
Serial.println(atof(data));
}
}
}
}
// Reset the buffer an clean the serial buffer
BufferCnt = 0;
Serial.flush();
} else {
// Fill the buffer with incoming data
buffer[BufferCnt] = incomingByte;
BufferCnt++;
}
}
}
bool isNumber(char *input) {
for (uint16_t i = 0; input[i] != '\0'; i++) {
if (isalpha(input[i]))
return false;
}
return true;
}
When I type AZ12 EL23 in the serial console, I got:
AZ: 12
EL: 34
But when I type AZ12 only (the ELxx command should be optional), I got "AZ: 12" on an Arduino Uno but the ESP8266 generates an exception:
Exception (28):
epc1=0x40201195 epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000000 depc=0x00000000
Would you please help me to sort this out?