MySensors Library & Examples  2.3.2
GatewayESP8266.ino
1 /*
2  * The MySensors Arduino library handles the wireless radio link and protocol
3  * between your home built sensors/actuators and HA controller of choice.
4  * The sensors forms a self healing radio network with optional repeaters. Each
5  * repeater and gateway builds a routing tables in EEPROM which keeps track of the
6  * network topology allowing messages to be routed to nodes.
7  *
8  * Created by Henrik Ekblad <[email protected]>
9  * Copyright (C) 2013-2019 Sensnology AB
10  * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors
11  *
12  * Documentation: http://www.mysensors.org
13  * Support Forum: http://forum.mysensors.org
14  *
15  * This program is free software; you can redistribute it and/or
16  * modify it under the terms of the GNU General Public License
17  * version 2 as published by the Free Software Foundation.
18  *
19  *******************************
20  *
21  * REVISION HISTORY
22  * Version 1.0 - Henrik Ekblad
23  * Contribution by a-lurker and Anticimex,
24  * Contribution by Norbert Truchsess <[email protected]>
25  * Contribution by Ivo Pullens (ESP8266 support)
26  *
27  * DESCRIPTION
28  * The EthernetGateway sends data received from sensors to the WiFi link.
29  * The gateway also accepts input on ethernet interface, which is then sent out to the radio network.
30  *
31  * VERA CONFIGURATION:
32  * Enter "ip-number:port" in the ip-field of the Arduino GW device. This will temporarily override any serial configuration for the Vera plugin.
33  * E.g. If you want to use the default values in this sketch enter: 192.168.178.66:5003
34  *
35  * LED purposes:
36  * - To use the feature, uncomment any of the MY_DEFAULT_xx_LED_PINs in your sketch, only the LEDs that is defined is used.
37  * - RX (green) - blink fast on radio message received. In inclusion mode will blink fast only on presentation received
38  * - TX (yellow) - blink fast on radio message transmitted. In inclusion mode will blink slowly
39  * - ERR (red) - fast blink on error during transmission error or receive crc error
40  *
41  * See https://www.mysensors.org/build/connect_radio for wiring instructions.
42  *
43  * If you are using a "barebone" ESP8266, see
44  * https://www.mysensors.org/build/esp8266_gateway#wiring-for-barebone-esp8266
45  *
46  * Inclusion mode button:
47  * - Connect GPIO5 (=D1) via switch to GND ('inclusion switch')
48  *
49  * Hardware SHA204 signing is currently not supported!
50  *
51  * Make sure to fill in your ssid and WiFi password below for ssid & pass.
52  */
53 
54 // Enable debug prints to serial monitor
55 #define MY_DEBUG
56 
57 // Use a bit lower baudrate for serial prints on ESP8266 than default in MyConfig.h
58 #define MY_BAUD_RATE 9600
59 
60 // Enables and select radio type (if attached)
61 #define MY_RADIO_RF24
62 //#define MY_RADIO_RFM69
63 //#define MY_RADIO_RFM95
64 
65 #define MY_GATEWAY_ESP8266
66 
67 #define MY_WIFI_SSID "MySSID"
68 #define MY_WIFI_PASSWORD "MyVerySecretPassword"
69 
70 // Enable UDP communication
71 //#define MY_USE_UDP // If using UDP you need to set MY_CONTROLLER_IP_ADDRESS or MY_CONTROLLER_URL_ADDRESS below
72 
73 // Set the hostname for the WiFi Client. This is the hostname
74 // it will pass to the DHCP server if not static.
75 #define MY_HOSTNAME "ESP8266_GW"
76 
77 // Enable MY_IP_ADDRESS here if you want a static ip address (no DHCP)
78 //#define MY_IP_ADDRESS 192,168,178,87
79 
80 // If using static ip you can define Gateway and Subnet address as well
81 //#define MY_IP_GATEWAY_ADDRESS 192,168,178,1
82 //#define MY_IP_SUBNET_ADDRESS 255,255,255,0
83 
84 // The port to keep open on node server mode
85 #define MY_PORT 5003
86 
87 // How many clients should be able to connect to this gateway (default 1)
88 #define MY_GATEWAY_MAX_CLIENTS 2
89 
90 // Controller ip address. Enables client mode (default is "server" mode).
91 // Also enable this if MY_USE_UDP is used and you want sensor data sent somewhere.
92 //#define MY_CONTROLLER_IP_ADDRESS 192, 168, 178, 68
93 //#define MY_CONTROLLER_URL_ADDRESS "my.controller.org"
94 
95 // Enable inclusion mode
96 //#define MY_INCLUSION_MODE_FEATURE
97 
98 // Enable Inclusion mode button on gateway
99 //#define MY_INCLUSION_BUTTON_FEATURE
100 // Set inclusion mode duration (in seconds)
101 //#define MY_INCLUSION_MODE_DURATION 60
102 // Digital pin used for inclusion mode button
103 //#define MY_INCLUSION_MODE_BUTTON_PIN D1
104 
105 // Set blinking period
106 //#define MY_DEFAULT_LED_BLINK_PERIOD 300
107 
108 // Flash leds on rx/tx/err
109 // Led pins used if blinking feature is enabled above
110 //#define MY_DEFAULT_ERR_LED_PIN 16 // Error led pin
111 //#define MY_DEFAULT_RX_LED_PIN 16 // Receive led pin
112 //#define MY_DEFAULT_TX_LED_PIN 16 // the PCB, on board LED
113 
114 #include <MySensors.h>
115 
116 void setup()
117 {
118  // Setup locally attached sensors
119 }
120 
122 {
123  // Present locally attached sensors here
124 }
125 
126 void loop()
127 {
128  // Send locally attached sensors data here
129 }
130 
API declaration for MySensors.
void setup()
Called after node initialises but before main loop.
void presentation()
Node presentation.
void loop()
Main loop.