MySensors Library & Examples
2.3.2-62-ge298769
examples
GatewayESP8266MQTTClient
GatewayESP8266MQTTClient.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-2022 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
*
24
* DESCRIPTION
25
* The ESP8266 MQTT gateway sends radio network (or locally attached sensors) data to your MQTT broker.
26
* The node also listens to MY_MQTT_TOPIC_PREFIX and sends out those messages to the radio network
27
*
28
* LED purposes:
29
* - To use the feature, uncomment any of the MY_DEFAULT_xx_LED_PINs in your sketch
30
* - RX (green) - blink fast on radio message received. In inclusion mode will blink fast only on presentation received
31
* - TX (yellow) - blink fast on radio message transmitted. In inclusion mode will blink slowly
32
* - ERR (red) - fast blink on error during transmission error or receive crc error
33
*
34
* See https://www.mysensors.org/build/connect_radio for wiring instructions.
35
*
36
* If you are using a "barebone" ESP8266, see
37
* https://www.mysensors.org/build/esp8266_gateway#wiring-for-barebone-esp8266
38
*
39
* Inclusion mode button:
40
* - Connect GPIO5 (=D1) via switch to GND ('inclusion switch')
41
*
42
* Hardware SHA204 signing is currently not supported!
43
*
44
* Make sure to fill in your ssid and WiFi password below for ssid & pass.
45
*/
46
47
// Enable debug prints to serial monitor
48
#define MY_DEBUG
49
50
// Use a bit lower baudrate for serial prints on ESP8266 than default in MyConfig.h
51
#define MY_BAUD_RATE 9600
52
53
// Enables and select radio type (if attached)
54
#define MY_RADIO_RF24
55
//#define MY_RADIO_RFM69
56
//#define MY_RADIO_RFM95
57
58
#define MY_GATEWAY_MQTT_CLIENT
59
#define MY_GATEWAY_ESP8266
60
61
// Set this node's subscribe and publish topic prefix
62
#define MY_MQTT_PUBLISH_TOPIC_PREFIX "mygateway1-out"
63
#define MY_MQTT_SUBSCRIBE_TOPIC_PREFIX "mygateway1-in"
64
65
// Set MQTT client id
66
#define MY_MQTT_CLIENT_ID "mysensors-1"
67
68
// Enable these if your MQTT broker requires username/password
69
//#define MY_MQTT_USER "username"
70
//#define MY_MQTT_PASSWORD "password"
71
72
// Set WIFI SSID and password
73
#define MY_WIFI_SSID "MySSID"
74
#define MY_WIFI_PASSWORD "MyVerySecretPassword"
75
76
// Set the hostname for the WiFi Client. This is the hostname
77
// passed to the DHCP server if not static.
78
#define MY_HOSTNAME "ESP8266_MQTT_GW"
79
80
// Enable MY_IP_ADDRESS here if you want a static ip address (no DHCP)
81
//#define MY_IP_ADDRESS 192,168,178,87
82
83
// If using static ip you can define Gateway and Subnet address as well
84
//#define MY_IP_GATEWAY_ADDRESS 192,168,178,1
85
//#define MY_IP_SUBNET_ADDRESS 255,255,255,0
86
87
// MQTT broker ip address.
88
#define MY_CONTROLLER_IP_ADDRESS 192, 168, 178, 68
89
90
//MQTT broker if using URL instead of ip address.
91
// #define MY_CONTROLLER_URL_ADDRESS "test.mosquitto.org"
92
93
// The MQTT broker port to to open
94
#define MY_PORT 1883
95
96
// Enable inclusion mode
97
//#define MY_INCLUSION_MODE_FEATURE
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
//#define MY_DEFAULT_ERR_LED_PIN 16 // Error led pin
110
//#define MY_DEFAULT_RX_LED_PIN 16 // Receive led pin
111
//#define MY_DEFAULT_TX_LED_PIN 16 // the PCB, on board LED
112
113
#include <
MySensors.h
>
114
115
void
setup
()
116
{
117
// Setup locally attached sensors
118
}
119
120
void
presentation
()
121
{
122
// Present locally attached sensors here
123
}
124
125
void
loop
()
126
{
127
// Send locally attached sensors data here
128
}
129
loop
void loop()
Main loop.
Definition:
GatewayESP8266MQTTClient.ino:125
presentation
void presentation()
Node presentation.
Definition:
GatewayESP8266MQTTClient.ino:120
setup
void setup()
Called after node initialises but before main loop.
Definition:
GatewayESP8266MQTTClient.ino:115
MySensors.h
API declaration for MySensors.
Copyright (C) 2013-2019 Sensnology AB. Generated by
doxygen
1.8.17