Topic: read the data from many ESP8266, sending all to cloud via one ESP8266
Hello,
I want to read the data from many other ESP8266 and send it to RemoteXY from one ESP8266 - ESP1 which is connected as shield on MEGA.
So I started from setting the communication between two ESP by using router. This example works:
http://www.instructables.com/id/WiFi-Co … sed-MCU-T/
I create few servers(these are virtual servers, I think) who send the data to 1 client - ESP1. But when I want to set RemoteXY also on ESP1 it don't work together at all.
Here can see my code, it not read data from other servers and do not connect to RemoteXY too.
Whit mark //R: WiFIEsp I show the place were I add commands to set connection to server.
Maybe it is because, WiFiEsp library do not work together with Remote XY.
/*
-- mega esp --
DHT: MEGA:
dat 52
*/
#define REMOTEXY_MODE__ESP8266_HARDSERIAL_CLOUD
#include <RemoteXY.h>
#include <SimpleDHT.h> //R: DHT:
#include "WiFiEsp.h" //R: WiFiEsp
// настройки соединения
#define REMOTEXY_SERIAL Serial1 // R: tas ir tie 19 un 18 pini
#define REMOTEXY_SERIAL_SPEED 9600
#define REMOTEXY_WIFI_SSID "XX_3_5"
#define REMOTEXY_WIFI_PASSWORD "XXXXXX"
#define REMOTEXY_CLOUD_SERVER "cloud.remotexy.com"
#define REMOTEXY_CLOUD_PORT XXXX
#define REMOTEXY_CLOUD_TOKEN "XXXXX"
// конфигурация интерфейса
#pragma pack(push, 1)
uint8_t RemoteXY_CONF[] =
{ 255,2,0,24,0,177,0,8,186,1,
2,0,3,52,22,11,2,26,31,31,
79,78,0,79,70,70,0,129,0,4,
47,13,3,29,109,101,103,97,32,108,
101,100,0,67,4,4,12,16,5,2,
26,6,129,0,4,7,17,3,29,109,
101,103,97,32,116,101,109,112,46,0,
67,4,4,25,16,5,2,26,6,129,
0,4,21,16,3,29,109,101,103,97,
32,109,105,116,114,46,0,67,4,38,
12,16,5,2,26,6,67,4,38,25,
16,5,2,26,6,129,0,38,8,16,
3,29,101,115,112,50,32,116,101,109,
112,46,0,129,0,38,21,15,3,29,
101,115,112,51,32,109,105,116,114,46,
0,2,0,38,52,22,11,2,26,31,
31,79,78,0,79,70,70,0,129,0,
39,47,13,3,29,101,115,112,50,32,
108,101,100,0 };
// структура определяет все переменные вашего интерфейса управления
struct {
// input variable
uint8_t mega_led; // =1 если переключатель включен и =0 если отключен
uint8_t esp2_led; // =1 если переключатель включен и =0 если отключен
// output variable
char temp_mega[6]; // =строка UTF8 оканчивающаяся нулем
char hum_mega[6]; // =строка UTF8 оканчивающаяся нулем
char temp_esp2[6]; // =строка UTF8 оканчивающаяся нулем
char hum_esp3[6]; // =строка UTF8 оканчивающаяся нулем
// other variable
uint8_t connect_flag; // =1 if wire connected, else =0
} RemoteXY;
#pragma pack(pop)
#define PIN_MEGA_LED 13
#define PIN_ESP2_LED 12//R: jalabo
//-----------------------------------------------------
//R: DHT pins:
int pinDHT22 = 52;
SimpleDHT22 dht22;
//-----------------------------------------------------
//R: WiFiEsp
int status = WL_IDLE_STATUS;
IPAddress serverESP2(192, 168, 8, 110); // the fix IP address of the server
// Initialize the Ethernet client object
WiFiEspClient client;
void setup()
{
RemoteXY_Init ();
pinMode (PIN_MEGA_LED, OUTPUT);
pinMode (PIN_ESP2_LED, OUTPUT);
//-----------------------------------------------------
//R: WiFiEsp
// initialize serial for debugging
Serial.begin(9600);
// initialize serial for ESP module
Serial1.begin(9600);
/*
// initialize ESP module
WiFi.init(&Serial1); //R: As soon as I add it the remotexy don't work
*/
}
void loop()
{
RemoteXY_Handler ();
digitalWrite(PIN_MEGA_LED, (RemoteXY.mega_led==0)?LOW:HIGH);
digitalWrite(PIN_ESP2_LED, (RemoteXY.esp2_led==0)?LOW:HIGH);
// TODO you loop code
//R: DHT:
float temperature = 0;
float humidity = 0;
int err = SimpleDHTErrSuccess;
if ((err = dht22.read2(pinDHT22, &temperature, &humidity, NULL)) != SimpleDHTErrSuccess) {
//delay(300);
return;
}
/* R: sending temp. un hum. to app:
преобразуем значение температуры в строку
и помещаем ее сразу в поле temp un hum структуры RemoteXY */
dtostrf((float)temperature, 0, 1, RemoteXY.temp_mega);
dtostrf((float)humidity, 0, 1, RemoteXY.hum_mega);
//-----------------------------------------------------------------------------------------
//R: WiFIEsp
client.connect(serverESP2, 80); // Connection to the server
Serial.println(".");
client.println("Hello server! Are you sleeping?\r"); // sends the message to the server
String answerESP2 = client.readStringUntil('\r'); // receives the answer from the sever
Serial.println("from server: " + answerESP2);
client.flush();
//--------------------------------------------------------------
}