MySensors Library & Examples  2.3.2
GatewayGSMMQTTClient.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 - Rait Lotamõis
23  *
24  * DESCRIPTION
25  * The TinyGSM MQTT gateway sends radio network (or locally attached sensors) data to your MQTT broker using a GSM modem or optionally an ESP8266 as a WiFi modem.
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 recieved. In inclusion mode will blink fast only on presentation recieved
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 recieve crc error
33  */
34 
35 
36 // Enable debug prints to serial monitor
37 #define MY_DEBUG
38 
39 // Enables and select radio type (if attached)
40 #define MY_RADIO_RF24
41 //#define MY_RADIO_RFM69
42 //#define MY_RADIO_RFM95
43 
44 #define MY_GATEWAY_MQTT_CLIENT
45 
46 // Enable GSM modem support
47 #define MY_GATEWAY_TINYGSM
48 
49 // Define your modem
50 #define TINY_GSM_MODEM_SIM800
51 // #define TINY_GSM_MODEM_SIM808
52 // #define TINY_GSM_MODEM_SIM900
53 // #define TINY_GSM_MODEM_A6
54 // #define TINY_GSM_MODEM_A7
55 // #define TINY_GSM_MODEM_M590
56 // #define TINY_GSM_ESP8266
57 
58 // leave empty anything that does not apply
59 #define MY_GSM_APN "internet"
60 //#define MY_GSM_PIN "1234"
61 #define MY_GSM_USR ""
62 //If using a GSM modem, this stands for your GSM connection password. If using WiFi, it's your wireless password.
63 #define MY_GSM_PSW ""
64 //#define MY_GSM_SSID ""
65 
66 // Use Hardware Serial on Mega, Leonardo, Micro
67 //#define SerialAT Serial1
68 // or Software Serial on Uno, Nano
69 #include <SoftwareSerial.h>
70 #define MY_GSM_RX 4
71 #define MY_GSM_TX 5
72 
73 // If your Mosquitto is old fashioned and does not support 3.1.1
74 //#define MQTT_VERSION MQTT_VERSION_3_1
75 
76 // Set this node's subscribe and publish topic prefix
77 #define MY_MQTT_PUBLISH_TOPIC_PREFIX "mygateway1-out"
78 #define MY_MQTT_SUBSCRIBE_TOPIC_PREFIX "mygateway1-in"
79 
80 // Set MQTT client id
81 #define MY_MQTT_CLIENT_ID "mysensors-1"
82 
83 // Enable these if your MQTT broker requires usenrame/password
84 //#define MY_MQTT_USER "username"
85 //#define MY_MQTT_PASSWORD "password"
86 
87 // Enable MY_IP_ADDRESS here if you want a static ip address (no DHCP)
88 //#define MY_IP_ADDRESS 192,168,32,220
89 
90 // If using static ip you can define Gateway and Subnet address as well
91 //#define MY_IP_GATEWAY_ADDRESS 192,168,32,1
92 //#define MY_IP_SUBNET_ADDRESS 255,255,255,0
93 
94 // MQTT broker ip address or url. Define one or the other.
95 //#define MY_CONTROLLER_URL_ADDRESS "mymqttbroker.com"
96 #define MY_CONTROLLER_IP_ADDRESS 192, 168, 178, 68
97 
98 // The MQTT broker port to to open
99 #define MY_PORT 1883
100 
101 /*
102 // Enable inclusion mode
103 #define MY_INCLUSION_MODE_FEATURE
104 // Enable Inclusion mode button on gateway
105 //#define MY_INCLUSION_BUTTON_FEATURE
106 // Set inclusion mode duration (in seconds)
107 #define MY_INCLUSION_MODE_DURATION 60
108 // Digital pin used for inclusion mode button
109 //#define MY_INCLUSION_MODE_BUTTON_PIN 3
110 
111 // Set blinking period
112 #define MY_DEFAULT_LED_BLINK_PERIOD 300
113 
114 // Flash leds on rx/tx/err
115 // Uncomment to override default HW configurations
116 //#define MY_DEFAULT_ERR_LED_PIN 16 // Error led pin
117 //#define MY_DEFAULT_RX_LED_PIN 16 // Receive led pin
118 //#define MY_DEFAULT_TX_LED_PIN 16 // the PCB, on board LED
119 */
120 
121 #include <MySensors.h>
122 
123 void setup()
124 {
125  // Setup locally attached sensors
126 }
127 
129 {
130  // Present locally attached sensors here
131 }
132 
133 void loop()
134 {
135  // Send locally attached sensors data here
136 }
137 
API declaration for MySensors.
void setup()
Called after node initialises but before main loop.
void presentation()
Node presentation.
void loop()
Main loop.