MySensors Library & Examples  2.3.2-36-g2e00bf6
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-2020 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 //#define MY_PJON
69 
70 #define MY_GATEWAY_MQTT_CLIENT
71 
72 // Set this node's subscribe and publish topic prefix
73 #define MY_MQTT_PUBLISH_TOPIC_PREFIX "mygateway1-out"
74 #define MY_MQTT_SUBSCRIBE_TOPIC_PREFIX "mygateway1-in"
75 
76 // Set MQTT client id
77 #define MY_MQTT_CLIENT_ID "mysensors-1"
78 
79 // W5100 Ethernet module SPI enable (optional if using a shield/module that manages SPI_EN signal)
80 //#define MY_W5100_SPI_EN 4
81 
82 // Enable Soft SPI for NRF radio (note different radio wiring is required)
83 // The W5100 ethernet module seems to have a hard time co-operate with
84 // radio on the same spi bus.
85 #if !defined(MY_W5100_SPI_EN) && !defined(ARDUINO_ARCH_SAMD)
86 #define MY_SOFTSPI
87 #define MY_SOFT_SPI_SCK_PIN 14
88 #define MY_SOFT_SPI_MISO_PIN 16
89 #define MY_SOFT_SPI_MOSI_PIN 15
90 #endif
91 
92 // When W5100 is connected we have to move CE/CSN pins for NRF radio
93 #ifndef MY_RF24_CE_PIN
94 #define MY_RF24_CE_PIN 5
95 #endif
96 #ifndef MY_RF24_CS_PIN
97 #define MY_RF24_CS_PIN 6
98 #endif
99 
100 // Enable these if your MQTT broker requires username/password
101 //#define MY_MQTT_USER "username"
102 //#define MY_MQTT_PASSWORD "password"
103 
104 // Enable MY_IP_ADDRESS here if you want a static ip address (no DHCP)
105 #define MY_IP_ADDRESS 192,168,178,87
106 
107 // If using static ip you can define Gateway and Subnet address as well
108 //#define MY_IP_GATEWAY_ADDRESS 192,168,178,1
109 //#define MY_IP_SUBNET_ADDRESS 255,255,255,0
110 
111 // MQTT broker ip address or url. Define one or the other.
112 //#define MY_CONTROLLER_URL_ADDRESS "m20.cloudmqtt.com"
113 #define MY_CONTROLLER_IP_ADDRESS 192, 168, 178, 68
114 
115 // The MQTT broker port to to open
116 #define MY_PORT 1883
117 
118 /*
119 // Enable inclusion mode
120 #define MY_INCLUSION_MODE_FEATURE
121 // Enable Inclusion mode button on gateway
122 //#define MY_INCLUSION_BUTTON_FEATURE
123 // Set inclusion mode duration (in seconds)
124 #define MY_INCLUSION_MODE_DURATION 60
125 // Digital pin used for inclusion mode button
126 //#define MY_INCLUSION_MODE_BUTTON_PIN 3
127 
128 // Set blinking period
129 #define MY_DEFAULT_LED_BLINK_PERIOD 300
130 
131 // Flash leds on rx/tx/err
132 // Uncomment to override default HW configurations
133 //#define MY_DEFAULT_ERR_LED_PIN 16 // Error led pin
134 //#define MY_DEFAULT_RX_LED_PIN 16 // Receive led pin
135 //#define MY_DEFAULT_TX_LED_PIN 16 // the PCB, on board LED
136 */
137 
138 #include <Ethernet.h>
139 #include <MySensors.h>
140 
141 void setup()
142 {
143  // Setup locally attached sensors
144 }
145 
147 {
148  // Present locally attached sensors here
149 }
150 
151 void loop()
152 {
153  // Send locally attached sensors data here
154 }
155 
loop
void loop()
Main loop.
Definition: GatewayW5100MQTTClient.ino:151
presentation
void presentation()
Node presentation.
Definition: GatewayW5100MQTTClient.ino:146
setup
void setup()
Called after node initialises but before main loop.
Definition: GatewayW5100MQTTClient.ino:141
MySensors.h
API declaration for MySensors.