All nodes i.e temperature sensors, boiler relay module, zone relay module etc. are scattered around the house that are responsible for controlling light, heating and other IOT devices serves very little purpose if we can not communicate with them or pass some instructions. Most of the time these devices are battery powered and even ones with main powered don’t communicate through home WiFi and for the battery powered nodes WiFi isn’t the option due to the fact how WiFi works even PiHome Smart Heating nodes aren’t WiFi connected.
Most of the time these IOT devices are connected through low powered nRF24L01 trans-receiver but on same time all these IOT nodes need to communicate with raspberry pi (controller). Now million dollar question: how we can communicate and pass some instructions to these IOT devices/nodes to have control on them? the simple solution that bridge the both worlds (nRF24L01 and WiFi/Ethernet) and to do this we need a device that can communicate to all IOT devices/nodes over nRF24L01 and to our controller over WiFi/Ethernet or serial, you may hear about it as Smart Home Gateway or simply IOT Gateway but its same thing so ultimately it communicate with all the nodes and on other side connect with your home automation controller either over WiFi, Ethernet or over serial port.
You can buy Smart Home Gateway from my PiHome store
Basic Configuration/Link between PiHome Smart Home Gateway, Nodes and Controller
PiHome Smart Heating Gateway has nRF24L01 to communicate with the nodes and Ethernet/WiFi to connect to the home network to which controller will also be connected. See image below for reference architecture, left side is temperature sensors node with NRF24L01 then in the middle you have PiHome Smart Heating Gateway or IOT Gateway that receive temperature readings from sensors node and then right side is your PiHome Smart Heating Controller software installed on raspberry pi that will process/digest these temperature readings and made decision for your heating needs.
PiHome Smart Heating Gateway is available to purchase from PiHome eBay Store, i m not making any money out of these sales, i m just trying to help all the creator/makers and get them to understand how this IOT stuff works and how they can have all connected devices by using the DIY skills.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
/* * Created by Henrik Ekblad <[email protected]> * Copyright (C) 2013-2018 Sensnology AB * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * version 2 as published by the Free Software Foundation. * * Make sure to fill in your ssid and WiFi password below for ssid & pass. */ // 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 // Enables and select radio type (if attached) #define MY_RADIO_RF24 //#define MY_RADIO_RFM69 #define MY_RF24_PA_LEVEL RF24_PA_MAX //#define MY_DEBUG_VERBOSE_RF24 // RF channel for the sensor net, 0-127 #define MY_RF24_CHANNEL 91 //RF24_250KBPS for 250kbs, RF24_1MBPS for 1Mbps, or RF24_2MBPS for 2Mbps #define RF24_DATARATE RF24_250KBPS #define MY_GATEWAY_ESP8266 #define MY_WIFI_SSID "MySSID" #define MY_WIFI_PASSWORD "MyVerySecretPassword" // Set the hostname for the WiFi Client. This is the hostname // it will pass to the DHCP server if not static. //#define MY_HOSTNAME "PiHome_Gateway" // The port to keep open on node server mode #define MY_PORT 5003 // How many clients should be able to connect to this gateway (default 1) #define MY_GATEWAY_MAX_CLIENTS 2 // Set blinking period #define MY_DEFAULT_LED_BLINK_PERIOD 300 // 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 #if defined(MY_USE_UDP) #include <WiFiUdp.h> #endif #include <ESP8266WiFi.h> #include <MySensors.h> void setup() { // Setup locally attached sensors } void presentation() { // Present locally attached sensors here } void loop() { // Send locally attached sensors data here } |
PiHome Smart Gateway is compatible with MySensors. For more information on how to communicate with smart home gateway check this post. For battery powered temperature sensors that runs on 18650 battery.
11 comments
good to see these pcb design, any time line for sale of these pre-built pcb?
Just checking… Would the wiring for the gateway be as it is described here:
https://diyprojects.io/mysensors-2-0-esp8266-wifi-gateway-domoticz/
?
Hi artlab,
can not verify this pin configuration, but i’ll update pin connections in next few days.
Lines #33 ":
#define MY_WIFI_SSID "MySSID"
#define MY_WIFI_PASSWORD "MyVerySecretPassword"
Should now (MySensors => v2.1.1?) be:
#define MY_ESP8266_SSID "my_wifi_id"
#define MY_ESP8266_PASSWORD "my_wifi_password"
(The github version is correct, BTW).
To get a static IP for the gateway, I needed to set that up before the wifi…
#define MY_GATEWAY_ESP8266
// Set the hostname for the WiFi Client. This is the hostname
// it will pass to the DHCP server if not static.
#define MY_ESP8266_HOSTNAME "PiHome_Gateway"
// Enable MY_IP_ADDRESS here if you want a static ip address (no DHCP)
#define MY_IP_ADDRESS 192, 168, 1, 150
// If using static ip you need to define Gateway and Subnet address as well
#define MY_IP_GATEWAY_ADDRESS 192, 168, 1, 254
#define MY_IP_SUBNET_ADDRESS 255, 255, 255, 0
#define MY_MAC_ADDRESS 0xDE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE //Your own MAC - check you router logs
// The port to keep open on node server mode
#define MY_PORT 5003
#define MY_ESP8266_SSID "MySSID"
#define MY_ESP8266_PASSWORD "MyWIFIPassword"
This might be a quirk of the MySensors library I am using…
Also worth noting, with Wemos D1 board, I had to regress the board definitions in the Arduino IDE to get it to compile, plus regress MySensors library to 2.1.1
Hope that helps someone! 🙂
artlab,
thank you, i dont have access to my usual stuff to check ms version i m using.
I spoke too soon regarding the static IP address… a couple of times now my gateway has arbitrarily decided to forget all about the IP address I’ve given it, and sneak off behind the bike sheds with the router to smoke some DHCP assigned IP – result: all communication from/to nodes stops dead.
WiFi. It just can’t be trusted.
Anyone had any luck with an ethernet gateway – specifically with the W5100 based board? I’ve had mixed results, I was wondering if anyone else has gone down the wired ethernet route?
My sketch:
#define MY_DEBUG
#define MY_RADIO_RF24
#define MY_RF24_PA_LEVEL RF24_PA_MAX
#define MY_RF24_CHANNEL 74
#define RF24_DATARATE RF24_250KBPS
#define MY_GATEWAY_W5100
#define MY_SOFTSPI
#define MY_SOFT_SPI_SCK_PIN 14
#define MY_SOFT_SPI_MISO_PIN 16
#define MY_SOFT_SPI_MOSI_PIN 15
#define MY_RF24_CE_PIN 5
#define MY_RF24_CS_PIN 6
#define MY_IP_ADDRESS 192,168,1,123
#define MY_IP_GATEWAY_ADDRESS 192,168,1,1
#define MY_IP_SUBNET_ADDRESS 255,255,255,0
#define MY_MAC_ADDRESS 0x85, 0xF6, 0xEB, 0x75, 0xCF, 0xD7
#define MY_PORT 5003
#define MY_DEFAULT_LED_BLINK_PERIOD 300
#include <Ethernet.h>
#include <MySensors.h>
void setup()
{
Serial.println("GatewayW5100v2 (Static IP - 123)");
}
void presentation()
{
}
void loop()
{
}
@artlab
i have tried using W5100 Ethernet shield for gateway but for some reason i can not make it stable, keep rebooting, power issues etc. i already blown two W5100. i didnt do anything special just followed instructions as per mysensors website yet manage to kill two of these after killing second W5100 i start to suspect may be they are 3.3v not 5.0v?
i m using wifi gateway and it is working perfect just reserved ip for gateway in router.
WRT the ESP8266 IP issue: When you load the board definitions (in my case, for Wemos D1) in Arduino IDE, there is an option under ‘Tools>Erase Flash’ for ‘Only Sketch’, ‘Sketch + WiFi Settings’ and ‘All Flash Contents’… when I found it I thought ‘Ah-ha!’ and tried the ‘Sketch + WiFi Settings’ option. It took the IP address I gave it, then on the second reboot it went back to using (what I think is) the very first DHCP assigned IP address it had when I first fired it up.
I wasn’t brave enough (yet) to try the ‘All Flash Contents’ option, for fear of hosing the bootloader or something, but I guess it’s either that or an exorcist.
I’ve had my W5100 gateway running for 2 days now without a hitch (so far).
The mysensors gateway howto suggested that the W5100 ran on 3.3v… I tried that first, but it would only dimly light the power LED.
Mine is clearly marked ‘+5v’ on the PCB, so I gave it that and it sprang to life.
I also gave the nRF module some screening – wrapped it in insulating tape, then a layer of aluminium foil tape (making sure it properly contacts the antenna base).
I gave it a 5mm RGB LED for an indicator (red = error, green = Tx, blue = Rx) – I had to put “#define MY_WITH_LEDS_BLINKING_INVERSE” in the sketch as I only had ‘common cathode (negative)’ RGB LEDs.
Here’s the current gateway sketch in full:
#define MY_DEBUG
#define MY_RADIO_RF24
#define MY_RF24_PA_LEVEL RF24_PA_MAX
#define MY_RF24_CHANNEL 74
#define RF24_DATARATE RF24_250KBPS
#define MY_GATEWAY_W5100
#define MY_SOFTSPI
#define MY_SOFT_SPI_SCK_PIN 14
#define MY_SOFT_SPI_MISO_PIN 16
#define MY_SOFT_SPI_MOSI_PIN 15
#define MY_RF24_CE_PIN 5
#define MY_RF24_CS_PIN 6
#define MY_IP_ADDRESS 192,168,1,123
#define MY_IP_GATEWAY_ADDRESS 192,168,1,1
#define MY_IP_SUBNET_ADDRESS 255,255,255,0
#define MY_MAC_ADDRESS 0x85, 0xF6, 0xEB, 0x75, 0xCF, 0xD7
#define MY_PORT 5003
#define MY_WITH_LEDS_BLINKING_INVERSE
#define MY_DEFAULT_LED_BLINK_PERIOD 300
#define MY_DEFAULT_ERR_LED_PIN 4 //red
#define MY_DEFAULT_TX_LED_PIN 3 //blue
#define MY_DEFAULT_RX_LED_PIN 2 //green
#include <Ethernet.h>
#include <MySensors.h>
void setup()
{
Serial.println("GatewayW5100v2.1 (Static IP - 123)");
}
void presentation()
{
}
void loop()
{
}
I’ll leave it running for a few more days, then if all’s OK I plan to add a Light Dependent Resistor (together with a fixed resistor to form a voltage divider – LDR between GND & A3, fixed or pot between A3 & VCC), read the value via A3 and map it to PWM on pin 10 (where I’ll connect the common negative of the LED) – this will automatically dim the status LED(s) down at night, as they’re fearsome bright at the moment and the constant flickering gets annoying.
The sketch for that (in case anyone’s interested):
`#define PWM_Pin 10 // All LED – side (enables brightness control of LEDs)
#define LDR_Pin A3 // The light sensor pin
byte PWM = 250; // Initial value (used by startupDelay LED flashing)
int LDR = 100; // Initial value (used by startupDelay LED flashing)
int LDR_low = 50; // The most ambient light (sunniest)
int LDR_high = 1000; // The least ambient light (darkest)
byte PWM_low = 50; // The brightest the LEDs will get (0 = full on, 255 = full off)
byte PWM_high = 253; // The dimmest the LEDs will get
void LDRRead() {
LDR = analogRead(LDR_Pin); // Read the voltage on the LDR pin x10, adding together
LDR = constrain(LDR, LDR_low, LDR_high); // Constain the result between ‘light’ and ‘dark’ ambient light levels
PWM = map(LDR, LDR_low, LDR_high, PWM_low, PWM_high); // Map those values to ‘bright’ and ‘dim’
analogWrite(PWM_Pin, PWM); // Write the result to the PWM pin
Serial.print(LDR);Serial.print(” “); Serial.println(PWM); // Tell me what you’re thinking… useful for setting LDR & PWM limits
}
void setup() {
Serial.begin(9600);
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
analogWrite(PWM_Pin, PWM); // This controls the brightness of all LEDs – this pin sinks current, so a higher number (0-255) means dimmer LEDs
}
void loop() {
LDRRead();
}
i tried 3.3v as well and results were same as yours hence 5v as i had +5v on both W5100 but then chip on 5v W5100 got very hot to touch and lived few seconds ;( may be i need to buy from different sources to give it one more try. thank you for sharing sketch.
I got my W5100 module from this seller – never had any problems with stuff from them, fairly quick delivery (to UK).
(Ethernet gateway is still running fine, by the way).
Are the .sch / .brd files are available for this combined Ethernet / Wifi gateway board?