Skip to content

Commit 5ebc1c8

Browse files
committed
Minor changes + reinserted led-blinking
1 parent 172d587 commit 5ebc1c8

File tree

3 files changed

+163
-111
lines changed

3 files changed

+163
-111
lines changed

MQTTGateway/MQTTGateway.ino

100644100755
+53-65
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,56 @@
1-
/* MyMQTT Gateway 0.1b
2-
3-
Created by Daniel Wiegert <[email protected]>
4-
Based on Mysensors Ethernet Gateway by Henrik Ekblad <[email protected]>
5-
Requires MySensors lib 1.4b
6-
http://www.mysensors.org
7-
8-
* Don't forget to look at the definitions in MyMQTT.h!
9-
* Don't forget to configure Radio pins, IP and MAC-address!
10-
11-
* Address-layout is : [MQTT_BROKER_PREFIX]/[NodeID]/[SensorID]/Light
12-
NodeID and SensorID is number (0-255).
13-
Last segment is translation of the sensor type, look inside MyMQTT.cpp for
14-
the definitions. User can change this to their needs.
15-
16-
Example openhab setup: http://www.openhab.org/
17-
18-
* openhab.cfg
19-
---
20-
mqtt:mysensor.url=tcp://192.168.0.234:1883
21-
mqtt:mysensor.clientId=MQTT
22-
---
23-
24-
* items/test.items
25-
---
26-
Group test
27-
Number Temp_test "Temp [%.1f °C]" (test) {mqtt="<[mysensor:MyMQTT/20/#/Temperature:state:default]"}
28-
Number Hum_test "Hum [%.1f %%]" (test) {mqtt="<[mysensor:MyMQTT/20/#/Humidity:state:default]"}
29-
Number test_test "test [%s]" (test) {mqtt="<[mysensor:MyMQTT/20/3/#:state:default]"}
30-
Switch sw1 "sw 1" (test) {<[mysensor:MyMQTT/21/1/Light:command:MAP(1.map)]"}
31-
--- (Note; # = Wildcard character)
32-
33-
* sitemap/test.site
34-
---
35-
sitemap demo label="Menu"
36-
Frame label="Openhab" {
37-
Group item=test label="Test group"
38-
}
39-
---
40-
41-
* transform/1.map
42-
---
43-
1=ON
44-
0=OFF
45-
---
46-
47-
* Features:
48-
- Supports automatic nodeID delegation
49-
- Recieve sketchname and version Example: (openhab item)
50-
String sketch20 "Node 20 Sketch name [%s]" (sketch,name,a) {mqtt="<[mysensor:MyMQTT/20/255/Sketch_name:state:default]"}
51-
String sketch21 "Node 21 Sketch name [%s]" (sketch,name,a) {mqtt="<[mysensor:MyMQTT/21/255/Sketch_name:state:default]"}
52-
[...]
53-
54-
* Todo:
55-
- DOCUMENTATION...
56-
- Special commands
57-
Read and set EEPROM Values
58-
Send Reboot, And reboot gateway itself.
59-
...
1+
// MyMQTT Gateway 0.1b
2+
//
3+
// Created by Daniel Wiegert <[email protected]>
4+
// Based on Mysensors Ethernet Gateway by Henrik Ekblad <[email protected]>
5+
// http://www.mysensors.org
6+
//
7+
// Requires MySensors lib 1.4b
8+
//
9+
// Don't forget to look at the definitions in MyMQTT.h!
10+
// Don't forget to configure Radio pins, IP and MAC-address!
11+
//
12+
// Address-layout is : [MQTT_BROKER_PREFIX]/[NodeID]/[SensorID]/Light
13+
// NodeID and SensorID is Decimal number.
14+
// Last segment is translation of the sensor type, look inside MyMQTT.cpp for
15+
// the definitions. User can change this to their needs.
16+
//
17+
// Features:
18+
// Supports automatic nodeID delegation
19+
// Recieve sketchname and version Example: (openhab item)
20+
//String sketch20 "Node 20 Sketch name [%s]" (sketch,name,a) {mqtt="<[mysensor:MyMQTT/20/255/Sketch_name:state:default]"}
21+
//String sketch21 "Node 21 Sketch name [%s]" (sketch,name,a) {mqtt="<[mysensor:MyMQTT/21/255/Sketch_name:state:default]"}
22+
// ...
23+
//
24+
// Todo:
25+
// DOCUMENTATION...
26+
// Special commands : clear or set EEPROM Values
27+
// Special commands : Reboot
28+
// ...
29+
/*
30+
Sketch uses 23,666 bytes (77%) of program storage space. Maximum is 30,720 bytes.
31+
Global variables use 766 bytes (37%) of dynamic memory, leaving 1,282 bytes for local variables. Maximum is 2,048 bytes.
6032
*/
6133

6234
#include <SPI.h>
6335
#include <MyMQTT.h>
6436
#include <Ethernet.h>
37+
#include <MsTimer2.h>
6538

6639

6740
// Use this for IBOARD modded to use standard MISO/MOSI/SCK More information see;
6841
// http://forum.mysensors.org/topic/224/iboard-cheap-single-board-ethernet-arduino-with-radio/5
69-
#define RADIO_CE_PIN 3 // radio chip enable
70-
#define RADIO_SPI_SS_PIN 8 // radio SPI serial select
42+
//#define RADIO_CE_PIN 3 // radio chip enable
43+
//#define RADIO_SPI_SS_PIN 8 // radio SPI serial select
44+
//#define RADIO_ERROR_LED_PIN A2 // Error led pin
45+
//#define RADIO_RX_LED_PIN A1 // Receive led pin
46+
//#define RADIO_TX_LED_PIN A0 // the PCB, on board LED
7147

7248
//Use this for default configured pro mini / nano etc :
73-
//#define RADIO_CE_PIN 5 // radio chip enable
74-
//#define RADIO_SPI_SS_PIN 6 // radio SPI serial select
49+
#define RADIO_CE_PIN 5 // radio chip enable
50+
#define RADIO_SPI_SS_PIN 6 // radio SPI serial select
51+
#define RADIO_ERROR_LED_PIN 7 // Error led pin
52+
#define RADIO_RX_LED_PIN 8 // Receive led pin
53+
#define RADIO_TX_LED_PIN 9 // the PCB, on board LED
7554

7655
#define IP_PORT 1883 // MQTT Listening port
7756
IPAddress myIp ( 192, 168, 0, 234 ); // Configure your static ip-address here
@@ -80,6 +59,8 @@ byte mac[] = { 0x02, 0xDE, 0xAD, 0x00, 0x00, 0x42 }; // Mac-address - Change th
8059

8160
EthernetServer server = EthernetServer(IP_PORT);
8261
MyMQTT gw(RADIO_CE_PIN, RADIO_SPI_SS_PIN);
62+
// Uncomment this constructor if you have leds and include button attached to your gateway
63+
// MyMQTT gw(RADIO_CE_PIN, RADIO_SPI_SS_PIN, RADIO_RX_LED_PIN, RADIO_TX_LED_PIN, RADIO_ERROR_LED_PIN);
8364

8465
void processEthernetMessages() {
8566
char inputString[MQTT_MAX_PACKET_SIZE] = "";
@@ -99,16 +80,23 @@ void writeEthernet(char *writeBuffer, int *writeSize) {
9980
server.write(writeBuffer, *writeSize); // Should this really be *writeSize?
10081
}
10182

83+
void ledTimersInterrupt() {
84+
gw.ledTimersInterrupt();
85+
}
86+
10287
int main(void) {
10388
init();
10489
Ethernet.begin(mac, myIp);
10590
delay(1000); // Wait for Ethernet to get configured.
10691
gw.begin(RF24_PA_LEVEL_GW, RF24_CHANNEL, RF24_DATARATE, writeEthernet);
10792
server.begin();
93+
if (gw.isLedMode()) {
94+
// Add led timer interrupt
95+
MsTimer2::set(300, ledTimersInterrupt);
96+
MsTimer2::start();
97+
}
10898
while (1) {
10999
processEthernetMessages();
110100
gw.processRadioMessage();
111101
}
112102
}
113-
114-

0 commit comments

Comments
 (0)