I am trying to create a transparent serial to WiFi bridge for use on a data collection system.
So I started with the WiFiTelnetToSerial example available inside Arduino (menu File/Examples/ESP8266WiFi/)
But when I am debugging this I have found that when the ESP8266 powers on there is some unintelligible data being sent out the serial port before my sketch starts sending debug data.
I have put this on top of the ino file in order to be able to send debug messages to the normal serial port:
#define DEBUGPORTS //Set this to use Serial as the debug port
#ifndef DEBUGPORTS
#define SerialDebug Serial1 // Debug goes out on GPIO02
#define SerialSS Serial // Device connected to the ESP UART
#else //For debugging inside Arduino
#define SerialDebug Serial // Debug goes out on ESP UART
#define SerialSS Serial1 // Device connected to GPIO02
#endif
So the Termite serial monitor (on Serial) should show what I print to the SerialDebug port.
This is what I have in the setrup() code:
void setup() {
String MsgDbg = ""; //Used for debug messages
EEPROM.begin(512); //Initialize EEPROM to load from flash and write changes later on
SerialDebug.begin(115200);
SerialDebug.println(""); // To get new line before printing debug messages
MsgDbg = "Starting TCP <-> UART bridge"; SerialDebug.println(MsgDbg);
.. then more diagnostic code
So the very first thing that happens after initializing the serial port is writing "Starting TCP <-> UART bridge"
But when I load the sketch and start it I do not see what I expect, instead of just my starting message I see a lot of stuff before it:
I am using the Termite serial monitor because it encloses non-displayable characters in brackets and shows them as hex code. So as far as I can tell the ESP8266 sends some kind of strange data out even before I gets into the setup() function!
I could count to these non-displayable characters with some data in between:
What can cause this and can it be switched off?
I cannot have the ESP8266 spew out these whenever it starts up because it will confuse the data collection equipment...
I haven't done anything with ESP8266 for over a year now but I remember there being some other stuff it prints at 115200 during a crash. It was always annoying to me that I got some gibberish no matter which baud rate I used. Maybe it would have all been at 115200 with a 40 MHz crystal.
So I probably need to add a gate with a delay to block all data for the initial say 1s then?
Not so good but doable on the TTL side of the RS232 converter, I guess. We need anyway to redesign the board for the new WiFi module.
Or maybe instead of a timer use a GPIO output which is activated inside the setup() function. When one gets there the extra output stuff should have been gone...
Note that I don't have the ESP AT firmware on it anymore, just the serial server sketch.
I am not clear as to when in the startup of the ESP-07 the execution reaches something that can be affected by user code. I believed it to be in the setup() function, bit it seems like the bogus data have already been transmitted when it reaches here.
So how could I execute a swap function in advance of setup()?
Or do you mean that the bogus data actually get sent at the instant I call:
SerialDebug.begin(115200);
That would make it even more mysterious to me, because where will the data get buffered in such a case waiting for begin()?
OTOH, a solution not needing to add a gate to the PCB would make it much more testable now before the revised PCB even exists...
So I tried to check this by moving my Tx connection on the breadboard and adding Serial.swap() before Serial.begin115200).
But meanwhile I had added a struct typedef which throws the strangest error I have seen...
The code:
typedef struct {
unsigned int chksum;
char[32] ssid;
char[32] passwd;
unsigned char[4] addr; //I tried with byte here but got the same error
unsigned long baud ;
unsigned int tcpport;
} ESPConfiguration;
When I build my sketch with this present I get this the error message:
TCP-UART_Bridge:63: error: expected unqualified-id before '[' token
unsigned char[4] addr;
I had tried byte too but with exactly the same error.
WTF?
I have Googled this but found no hit looking like this....
typedef struct {
unsigned int chksum;
char ssid[32];
char passwd[32];
unsigned char addr[4]; //I tried with byte here but got the same error
unsigned long baud ;
unsigned int tcpport;
} ESPConfiguration;
Well I want to separate the definitions and usage in h vs c files (and ino).
Now I have put this into the espconfig.h file:
typedef struct
{
unsigned int chksum;
char[32] ssid;
char[32] passwd;
byte[4] addr;
long baud;
unsigned int tcpport;
} ESPConfiguration; //76 bytes
The h file is included both in the main ino file and in the espconfig.c file where the struct variable will be used for processing the WiFi configuration. But the variable itself is declared in the ino file so it will become global.
I have now chnaged to byte[4] again, but I find the errors appearing anyway:
Arduino: 1.8.2 (Windows 7), Board: "Generic ESP8266 Module, 80 MHz, ck, 26 MHz, 40MHz, DIO, 4M (1M SPIFFS), v2 Prebuilt (MSS=536), Disabled, None, 115200"
In file included from sketch\espconfig.c:5:0:
sketch\espconfig.h:19:7: error: expected identifier or '(' before '[' token
char[32] ssid;
^
sketch\espconfig.h:20:7: error: expected identifier or '(' before '[' token
char[32] passwd;
^
sketch\espconfig.h:21:3: error: expected ';' before 'byte'
byte[4] addr;
^
exit status 1
Somehow it really looks like Arduino does not like 8 bit data (char or byte)...
But I thought these were really basic items when programming.
unsigned int chksum;
char ssid[32];
char passwd[32];
unsigned char addr[4]; //I tried with byte here but got the same error
unsigned long baud ;
unsigned int tcpport;
} ESPConfiguration;
Sorry, I did not see your changes to the placement of []....
I'm switching languages too frequently.
Need some sleep. It is 1 AM here now.
But now the strange error is no longer reported, instead it errors out in a few assignments from String to the struct members ssid and passwd. I have to dig up how to assign between text variables tomorrow.