MySensors Library & Examples  2.3.2
GatewayW5100MQTTClient.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  *
24  * DESCRIPTION
25  * The W5100 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 WITH_LEDS_BLINKING in MyConfig.h
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 http://www.mysensors.org/build/esp8266_gateway for wiring instructions.
35  * nRF24L01+ ESP8266
36  * VCC VCC
37  * CE GPIO4
38  * CSN/CS GPIO15
39  * SCK GPIO14
40  * MISO GPIO12
41  * MOSI GPIO13
42  *
43  * Not all ESP8266 modules have all pins available on their external interface.
44  * This code has been tested on an ESP-12 module.
45  * The ESP8266 requires a certain pin configuration to download code, and another one to run code:
46  * - Connect REST (reset) via 10K pullup resistor to VCC, and via switch to GND ('reset switch')
47  * - Connect GPIO15 via 10K pulldown resistor to GND
48  * - Connect CH_PD via 10K resistor to VCC
49  * - Connect GPIO2 via 10K resistor to VCC
50  * - Connect GPIO0 via 10K resistor to VCC, and via switch to GND ('bootload switch')
51  *
52  * Inclusion mode button:
53  * - Connect GPIO5 via switch to GND ('inclusion switch')
54  *
55  * Hardware SHA204 signing is currently not supported!
56  *
57  * Make sure to fill in your ssid and WiFi password below for ssid & pass.
58  */
59 
60 
61 // Enable debug prints to serial monitor
62 #define MY_DEBUG
63 
64 // Enables and select radio type (if attached)
65 #define MY_RADIO_RF24
66 //#define MY_RADIO_RFM69
67 //#define MY_RADIO_RFM95
68 
69 #define MY_GATEWAY_MQTT_CLIENT
70 
71 // Set this node's subscribe and publish topic prefix
72 #define MY_MQTT_PUBLISH_TOPIC_PREFIX "mygateway1-out"
73 #define MY_MQTT_SUBSCRIBE_TOPIC_PREFIX "mygateway1-in"
74 
75 // Set MQTT client id
76 #define MY_MQTT_CLIENT_ID "mysensors-1"
77 
78 // W5100 Ethernet module SPI enable (optional if using a shield/module that manages SPI_EN signal)
79 //#define MY_W5100_SPI_EN 4
80 
81 // Enable Soft SPI for NRF radio (note different radio wiring is required)
82 // The W5100 ethernet module seems to have a hard time co-operate with
83 // radio on the same spi bus.
84 #if !defined(MY_W5100_SPI_EN) && !defined(ARDUINO_ARCH_SAMD)
85 #define MY_SOFTSPI
86 #define MY_SOFT_SPI_SCK_PIN 14
87 #define MY_SOFT_SPI_MISO_PIN 16
88 #define MY_SOFT_SPI_MOSI_PIN 15
89 #endif
90 
91 // When W5100 is connected we have to move CE/CSN pins for NRF radio
92 #ifndef MY_RF24_CE_PIN
93 #define MY_RF24_CE_PIN 5
94 #endif
95 #ifndef MY_RF24_CS_PIN
96 #define MY_RF24_CS_PIN 6
97 #endif
98 
99 // Enable these if your MQTT broker requires username/password
100 //#define MY_MQTT_USER "username"
101 //#define MY_MQTT_PASSWORD "password"
102 
103 // Enable MY_IP_ADDRESS here if you want a static ip address (no DHCP)
104 #define MY_IP_ADDRESS 192,168,178,87
105 
106 // If using static ip you can define Gateway and Subnet address as well
107 //#define MY_IP_GATEWAY_ADDRESS 192,168,178,1
108 //#define MY_IP_SUBNET_ADDRESS 255,255,255,0
109 
110 // MQTT broker ip address or url. Define one or the other.
111 //#define MY_CONTROLLER_URL_ADDRESS "m20.cloudmqtt.com"
112 #define MY_CONTROLLER_IP_ADDRESS 192, 168, 178, 68
113 
114 // The MQTT broker port to to open
115 #define MY_PORT 1883
116 
117 /*
118 // Enable inclusion mode
119 #define MY_INCLUSION_MODE_FEATURE
120 // Enable Inclusion mode button on gateway
121 //#define MY_INCLUSION_BUTTON_FEATURE
122 // Set inclusion mode duration (in seconds)
123 #define MY_INCLUSION_MODE_DURATION 60
124 // Digital pin used for inclusion mode button
125 //#define MY_INCLUSION_MODE_BUTTON_PIN 3
126 
127 // Set blinking period
128 #define MY_DEFAULT_LED_BLINK_PERIOD 300
129 
130 // Flash leds on rx/tx/err
131 // Uncomment to override default HW configurations
132 //#define MY_DEFAULT_ERR_LED_PIN 16 // Error led pin
133 //#define MY_DEFAULT_RX_LED_PIN 16 // Receive led pin
134 //#define MY_DEFAULT_TX_LED_PIN 16 // the PCB, on board LED
135 */
136 
137 #include <Ethernet.h>
138 #include <MySensors.h>
139 
140 void setup()
141 {
142  // Setup locally attached sensors
143 }
144 
146 {
147  // Present locally attached sensors here
148 }
149 
150 void loop()
151 {
152  // Send locally attached sensors data here
153 }
154 
loop
void loop()
Main loop.
Definition: GatewayW5100MQTTClient.ino:150
presentation
void presentation()
Node presentation.
Definition: GatewayW5100MQTTClient.ino:145
setup
void setup()
Called after node initialises but before main loop.
Definition: GatewayW5100MQTTClient.ino:140
MySensors.h
API declaration for MySensors.