I can program it correctly and wondering how to execute the following scenario.
I run openHAB for home automation which can be interfaced over TCP/IP either though MQTT or RESTful API.
I want to use an Arduino Mega as my hub to monitor all my hardwired sensors via the GPIOs. The items connected to the GPIOs would be door sensors and motion sensors. When the arduino detects motion for the PIRs or a door opened/closed i want to send either a MQTT message or REST command to my openHAB server.
Does anyone have an example on to to do this, all i'm really looking for is an example sketch that monitors the GPIO on the Arduino and then sends either a REST command or MQTT message over the ESP8266 depending on the state changed.
I think that at that board it is possible to connect esp with atmega's Serial3. the esp has only one Serial.
with Firmata option you would always switch the dip for esp between atmega and usb. or you would use ota upload of the esp sketch.
with WiFi Link you upload the esp firmware and then you connect esp to Serial3 and atmega to usb. and you write your sketch with a good WiFi library, upload it and debug. business as usual. no dip switch flipping.
Juraj:
I think that at that board it is possible to connect esp with atmega's Serial3. the esp has only one Serial.
Yeah it appears so, i been following some sample sketches i found and when i have dip switch 1,2,3,4 set to ON and the rest OFF it allows communication: USB <-> ATmega2560 <-> ESP8266
The sample sketch i'm using is one that connects the ESP to wifi and makes a simple webserver, then i upload a sketch to the ATMega2560 and within the webserver i can click a On/OFF button which turns the internal LED ON/OFF.
The last point you have in regards to WiFi Link, would all the code reside on the ESP and you read serial3 for the GPIO's? I'm just trying to comprehend how the ESP interacts with the Mega. As i assume they are two independent units and i need to set each up individually and then make them talk together. correct me if im wrong.
Pythong:
The last point you have in regards to WiFi Link, would all the code reside on the ESP and you read serial3 for the GPIO's?
it would be the case with Firmata handling the Atmega, not WiFi Link
Pythong:
I'm just trying to comprehend how the ESP interacts with the Mega. As i assume they are two independent units and i need to set each up individually and then make them talk together. correct me if im wrong.
When i try to verify/compile WiFi Link Firmware i get the following error any idea why?
Build options changed, rebuilding all
In file included from C:\Users\Chris\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.2.0\libraries\ESP8266WiFi\src/ESP8266WiFi.h:39:0,
from sketch\CommLgc.h:25,
from sketch\CommLgc.cpp:25:
C:\Users\Chris\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.2.0\libraries\ESP8266WiFi\src/WiFiClient.h: In instantiation of 'size_t WiFiClient::write(T&, size_t) [with T = unsigned char [128]; size_t = unsigned int]':
sketch\CommLgc.cpp:750:121: required from here
C:\Users\Chris\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.2.0\libraries\ESP8266WiFi\src/WiFiClient.h:123:36: error: request for member 'available' in 'source', which is of non-class type 'unsigned char [128]'
size_t left = source.available();
^
C:\Users\Chris\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.2.0\libraries\ESP8266WiFi\src/WiFiClient.h:127:5: error: request for member 'read' in 'source', which is of non-class type 'unsigned char [128]'
source.read(buffer.get(), will_send);
^
exit status 1
Error compiling for board Generic ESP8266 Module.
Juraj:
RC2 is better. with RC1 I had connection stability isues
Thank you for your help. I have been running this setup for a while and been trying to diagnose some problems where my MQTT messages stop sending. Wifi isn't dropped.
I'm thinking of sending my messages over restFUL but can't find a compatible library that works with WiFiLink. Do you have any rest libraries you recommend me try?