Hi,
First, I will try to explain what I want to achieve. I'm making two controllers for detecting status of floor heating actuators (two floor house). Actuators are powered by 230V. I'm going to use 230V AC to 5V DC converters, so when actuator is open, arduino INPUT will be HIGH.
First controller will request a status of second floor controller, if all actuators are OFF, controller will disable boiler heating function.
I have two of these https://robotdyn.com/uno-wifi-r3-atmega328p-esp8266-32mb-flash-usb-ttl-ch340g-micro-usb.html
My main problem is send and receive serial data between esp and ATmega328P. Very often I'm unable to read received data (e.g I should get <1010>, but getting <?000>, and sometimes data is valid...)
Here is code sample of esp module:
#include <ESP8266WiFi.h>
char ssid[] = "*******";
char pass[] = "******";
IPAddress server(*******);
WiFiClient client;
const char startOfNumberDelimiter = '<';
const char endOfNumberDelimiter = '>';
const char startOfClientDataDelimiter = '[';
const char endOfClientDataDelimiter = ']';
bool receiveSerialData = false;
bool receiveClientData = false;
void setup() {
Serial.begin(115200);
WiFi.begin(ssid, pass);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
}
}
void loop () {
//wait for data from arduino (serial.print() char array)
while (Serial.available() > 0) {
char character = Serial.read();
if (character == startOfNumberDelimiter) {
receiveSerialData = true;
client.connect(server, 80);
}
if (receiveSerialData) {
client.print(character);
}
if (character == endOfNumberDelimiter) {
receiveSerialData = false;
client.flush();
break;
}
}
char serverData = client.read();
//using different delimitter to avoid sending same data again
if (serverData == startOfClientDataDelimiter) {
receiveClientData = true;
}
if (receiveClientData) {
Serial.print(serverData);
}
if (serverData == endOfClientDataDelimiter) {
receiveClientData = false;
}
}
Can you advice any trustful methods sending data over serial?
I guess it would be much easier to use something like NodeMCU, but it is only 3.3V