How to tell to an ESP8266 node who is its ESP8266 Wifi gateway? Or each ESP8266 is a gateway for itself?
-
Hello,
I created an ESP8266 Wifi gateway and everything is working very well.
Now I need to create a node: mi question is... what the directive to say to the node who is its gateway?
Or every ESP8266 has to be a gateway for itself?I'm using Openhab2.
This is my sketch, what I'm missing, please? My gateway as 192.168.0.95 as IP address
// Enable debug prints to serial monitor
#define MY_DEBUG// Use a bit lower baudrate for serial prints on ESP8266 than default in MyConfig.h
#define MY_BAUD_RATE 9600// Enable and select radio type attached
//#define MY_RADIO_RF24
//#define MY_RADIO_NRF5_ESB
//#define MY_RADIO_RFM69
//#define MY_RADIO_RFM95
//#define MY_GATEWAY_ESP8266#define MY_WIFI_SSID "xxxx"
#define MY_WIFI_PASSWORD "xxx"// Enable MY_IP_ADDRESS here if you want a static ip address (no DHCP)
#define MY_IP_ADDRESS 192,168,0,88// If using static ip you can define Gateway and Subnet address as well
#define MY_IP_GATEWAY_ADDRESS 192,168,0,1
#define MY_IP_SUBNET_ADDRESS 255,255,255,0// Flash leds on rx/tx/err
// Led pins used if blinking feature is enabled above
#define MY_DEFAULT_ERR_LED_PIN 16 // Error led pin
#define MY_DEFAULT_RX_LED_PIN 16 // Receive led pin
#define MY_DEFAULT_TX_LED_PIN 16 // the PCB, on board LED#define MY_NODE_ID 1
#if defined(MY_USE_UDP)
#include <WiFiUdp.h>
#endif#include <ESP8266WiFi.h>
#include <MySensors.h>
#include <ArduinoOTA.h>#define RELAY1 12
#define RELAY2 13#define RELAY_ON 1 // GPIO value to write to turn on attached relay
#define RELAY_OFF 0 // GPIO value to write to turn off attached relayvoid before()
{
pinMode(RELAY1,OUTPUT);
pinMode(RELAY2,OUTPUT);
digitalWrite(RELAY1, loadState(RELAY1)?RELAY_OFF:RELAY_ON);
digitalWrite(RELAY2, loadState(RELAY2)?RELAY_OFF:RELAY_ON);
}void setup()
{
}void presentation()
{
// Send the sketch version information to the gateway and Controller
sendSketchInfo("LuciFinestrone", "1.0");present(RELAY1, S_BINARY, "luceFinestrone",true); //present(RELAY2, S_BINARY, "light2",true);}
void loop()
{
}void receive(const MyMessage &message)
{
// We only expect one type of message from controller. But we better check anyway.
if (message.type==V_STATUS) {
// Change relay state
digitalWrite(message.sensor, message.getBool()?RELAY_ON:RELAY_OFF);
// Store state in eeprom
saveState(message.sensor, message.getBool());
// Write some debug info
Serial.print("Incoming change for sensor:");
Serial.print(message.sensor);
Serial.print(", New status: ");
Serial.println(message.getBool());
}
} -
Hello,
I created an ESP8266 Wifi gateway and everything is working very well.
Now I need to create a node: mi question is... what the directive to say to the node who is its gateway?
Or every ESP8266 has to be a gateway for itself?I'm using Openhab2.
This is my sketch, what I'm missing, please? My gateway as 192.168.0.95 as IP address
// Enable debug prints to serial monitor
#define MY_DEBUG// Use a bit lower baudrate for serial prints on ESP8266 than default in MyConfig.h
#define MY_BAUD_RATE 9600// Enable and select radio type attached
//#define MY_RADIO_RF24
//#define MY_RADIO_NRF5_ESB
//#define MY_RADIO_RFM69
//#define MY_RADIO_RFM95
//#define MY_GATEWAY_ESP8266#define MY_WIFI_SSID "xxxx"
#define MY_WIFI_PASSWORD "xxx"// Enable MY_IP_ADDRESS here if you want a static ip address (no DHCP)
#define MY_IP_ADDRESS 192,168,0,88// If using static ip you can define Gateway and Subnet address as well
#define MY_IP_GATEWAY_ADDRESS 192,168,0,1
#define MY_IP_SUBNET_ADDRESS 255,255,255,0// Flash leds on rx/tx/err
// Led pins used if blinking feature is enabled above
#define MY_DEFAULT_ERR_LED_PIN 16 // Error led pin
#define MY_DEFAULT_RX_LED_PIN 16 // Receive led pin
#define MY_DEFAULT_TX_LED_PIN 16 // the PCB, on board LED#define MY_NODE_ID 1
#if defined(MY_USE_UDP)
#include <WiFiUdp.h>
#endif#include <ESP8266WiFi.h>
#include <MySensors.h>
#include <ArduinoOTA.h>#define RELAY1 12
#define RELAY2 13#define RELAY_ON 1 // GPIO value to write to turn on attached relay
#define RELAY_OFF 0 // GPIO value to write to turn off attached relayvoid before()
{
pinMode(RELAY1,OUTPUT);
pinMode(RELAY2,OUTPUT);
digitalWrite(RELAY1, loadState(RELAY1)?RELAY_OFF:RELAY_ON);
digitalWrite(RELAY2, loadState(RELAY2)?RELAY_OFF:RELAY_ON);
}void setup()
{
}void presentation()
{
// Send the sketch version information to the gateway and Controller
sendSketchInfo("LuciFinestrone", "1.0");present(RELAY1, S_BINARY, "luceFinestrone",true); //present(RELAY2, S_BINARY, "light2",true);}
void loop()
{
}void receive(const MyMessage &message)
{
// We only expect one type of message from controller. But we better check anyway.
if (message.type==V_STATUS) {
// Change relay state
digitalWrite(message.sensor, message.getBool()?RELAY_ON:RELAY_OFF);
// Store state in eeprom
saveState(message.sensor, message.getBool());
// Write some debug info
Serial.print("Incoming change for sensor:");
Serial.print(message.sensor);
Serial.print(", New status: ");
Serial.println(message.getBool());
}
}
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login