Skip to content

Instantly share code, notes, and snippets.

@Apocrathia
Last active March 25, 2016 12:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Apocrathia/73e9c9c9eb28bc2a1055 to your computer and use it in GitHub Desktop.
Save Apocrathia/73e9c9c9eb28bc2a1055 to your computer and use it in GitHub Desktop.
MySensors Setup
/**
* The MySensors Arduino library handles the wireless radio link and protocol
* between your home built sensors/actuators and HA controller of choice.
* The sensors forms a self healing radio network with optional repeaters. Each
* repeater and gateway builds a routing tables in EEPROM which keeps track of the
* network topology allowing messages to be routed to nodes.
*
* Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
* Copyright (C) 2013-2015 Sensnology AB
* Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
*
* Documentation: http://www.mysensors.org
* Support Forum: http://forum.mysensors.org
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 2 as published by the Free Software Foundation.
*
*******************************
*
* DESCRIPTION
*
* Example sketch showing how to send in DS1820B OneWire temperature readings back to the controller
* http://www.mysensors.org/build/temp
*/
#include <MySensor.h>
#include <SPI.h>
#include <DallasTemperature.h>
#include <OneWire.h>
#define COMPARE_TEMP 1 // Send temperature only if changed? 1 = Yes 0 = No
#define ONE_WIRE_BUS 3 // Pin where dallase sensor is connected
#define MAX_ATTACHED_DS18B20 16
unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds)
OneWire oneWire(ONE_WIRE_BUS); // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
DallasTemperature sensors(&oneWire); // Pass the oneWire reference to Dallas Temperature.
MySensor gw;
float lastTemperature[MAX_ATTACHED_DS18B20];
int numSensors=0;
boolean receivedConfig = false;
boolean metric = true;
// Initialize temperature message
MyMessage msg(0,V_TEMP);
void setup()
{
// Startup up the OneWire library
sensors.begin();
// requestTemperatures() will not block current thread
sensors.setWaitForConversion(false);
// Startup and initialize MySensors library. Set callback for incoming messages.
gw.begin();
// Send the sketch version information to the gateway and Controller
gw.sendSketchInfo("Temperature Sensor", "1.1");
// Fetch the number of attached temperature sensors
numSensors = sensors.getDeviceCount();
// Present all sensors to controller
for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) {
gw.present(i, S_TEMP);
}
}
void loop()
{
// Process incoming messages (like config from server)
gw.process();
// Fetch temperatures from Dallas sensors
sensors.requestTemperatures();
// query conversion time and sleep until conversion completed
int16_t conversionTime = sensors.millisToWaitForConversion(sensors.getResolution());
// sleep() call can be replaced by wait() call if node need to process incoming messages (or if node is repeater)
gw.sleep(conversionTime);
// Read temperatures and send them to controller
for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) {
// Fetch and round temperature to one decimal
float temperature = static_cast<float>(static_cast<int>((gw.getConfig().isMetric?sensors.getTempCByIndex(i):sensors.getTempFByIndex(i)) * 10.)) / 10.;
// Only send data if temperature has changed and no error
#if COMPARE_TEMP == 1
if (lastTemperature[i] != temperature && temperature != -127.00 && temperature != 85.00) {
#else
if (temperature != -127.00 && temperature != 85.00) {
#endif
// Send in the new temperature
gw.send(msg.setSensor(i).set(temperature,1));
// Save new temperatures for next compare
lastTemperature[i]=temperature;
}
}
gw.sleep(SLEEP_TIME);
}
/**
* The MySensors Arduino library handles the wireless radio link and protocol
* between your home built sensors/actuators and HA controller of choice.
* The sensors forms a self healing radio network with optional repeaters. Each
* repeater and gateway builds a routing tables in EEPROM which keeps track of the
* network topology allowing messages to be routed to nodes.
*
* Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
* Copyright (C) 2013-2015 Sensnology AB
* Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
*
* Documentation: http://www.mysensors.org
* Support Forum: http://forum.mysensors.org
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 2 as published by the Free Software Foundation.
*
*******************************
*
* REVISION HISTORY
* Version 1.0 - Created by Daniel Wiegert <daniel.wiegert@gmail.com>
*
* DESCRIPTION
* MyMQTT Broker Gateway 0.1b
* Latest instructions found here:
* http://www.mysensors.org/build/mqtt_gateway
* http://www.mysensors.org/build/ethernet_gateway
*
* Change below; TCP_IP, TCP_PORT, TCP_MAC
* This will listen on your selected TCP_IP:TCP_PORT below, Please change TCP_MAC your liking also.
* 1 -> NOTE: Keep first byte at x2, x6, xA or xE (replace x with any hex value) for using Local Ranges.
* 2 You can use standard pin set-up as MySensors recommends or if you own a IBOARD you may change
* the radio-pins below if you hardware mod your iBoard. see [URL BELOW] for more details.
* http://forum.mysensors.org/topic/224/iboard-cheap-single-board-ethernet-arduino-with-radio/5
*
* Don't forget to look at the definitions in MyMQTT.h!
*
* define TCPDUMP and connect serial interface if you have problems, please write on
* http://forum.mysensors.org/ and explain your problem, include serial output. Don't forget to
* turn on DEBUG in libraries\MySensors\MyConfig.h also.
*
* MQTT_FIRST_SENSORID is for 'DHCP' server in MyMQTT. You may limit the ID's with FIRST and LAST definition.
* If you want your manually configured below 20 set MQTT_FIRST_SENSORID to 20.
* To disable: set MQTT_FIRST_SENSORID to 255.
*
* MQTT_BROKER_PREFIX is the leading prefix for your nodes. This can be only one char if like.
*
* MQTT_SEND_SUBSCRIPTION is if you want the MyMQTT to send a empty payload message to your nodes.
* This can be useful if you want to send latest state back to the MQTT client. Just check if incoming
* message has any length or not.
* Example: if (msg.type==V_LIGHT && strlen(msg.getString())>0) otherwise the code might do strange things.
*
* (*) Address-layout is : [MQTT_BROKER_PREFIX]/[NodeID]/[SensorID]/V_[SensorType]
* NodeID and SensorID is uint8 (0-255) number.
* Last segment is translation of the sensor type, look inside MyMQTT.cpp for the definitions.
* User can change this to their needs. We have also left some space for custom types.
*
* Special: (sensor 255 reserved for special commands)
* You can receive a node sketch name with MyMQTT/20/255/V_Sketch_name (or version with _version)
*
* To-do:
* Special commands : clear or set EEPROM Values, Send REBOOT and Receive reboot for MyMQTT itself.
* Be able to send ACK so client returns the data being sent.
* ... Please come with ideas!
* What to do with publish messages.
*
* Test in more MQTT clients, So far tested in openhab and MyMQTT for Android (Not my creation)
* - http://www.openhab.org/
* - https://play.google.com/store/apps/details?id=at.tripwire.mqtt.client&hl=en
* ... Please notify me if you use this broker with other software.
*
* How to set-up Openhab and MQTTGateway:
* http://forum.mysensors.org/topic/303/mqtt-broker-gateway
*/
#include <DigitalIO.h>
#include <SPI.h>
#include <MySigningNone.h>
#include <MyTransportRFM69.h>
#include <MyTransportNRF24.h>
#include <MyHwATMega328.h>
#include <MySigningAtsha204Soft.h>
#include <MySigningAtsha204.h>
#include <MySensor.h>
#include <MsTimer2.h>
#include <Ethernet.h>
#include "MyMQTT.h"
#define INCLUSION_MODE_TIME 1 // Number of minutes inclusion mode is enabled
#define INCLUSION_MODE_PIN 3 // Digital pin used for inclusion mode button
// * Use this for IBOARD modded to use standard MISO/MOSI/SCK, see note *1 above!
/*
#define RADIO_CE_PIN 3 // radio chip enable
#define RADIO_SPI_SS_PIN 8 // radio SPI serial select
#define RADIO_ERROR_LED_PIN A2 // Error led pin
#define RADIO_RX_LED_PIN A1 // Receive led pin
#define RADIO_TX_LED_PIN A0 // the PCB, on board LED
*/
// * Use this for default configured pro mini / nano etc :
///*
#define RADIO_CE_PIN 5 // radio chip enable
#define RADIO_SPI_SS_PIN 6 // radio SPI serial select
#define RADIO_ERROR_LED_PIN 7 // Error led pin
#define RADIO_RX_LED_PIN 8 // Receive led pin
#define RADIO_TX_LED_PIN 9 // the PCB, on board LED*/
#define TCP_PORT 1883 // Set your MQTT Broker Listening port.
IPAddress TCP_IP ( 10, 0, 1, 79 ); // Configure your static ip-address here
byte TCP_MAC[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0x00, 0x01 }; // Mac-address - You should change this! see note *2 above!
//////////////////////////////////////////////////////////////////
// NRFRF24L01 radio driver (set low transmit power by default)
MyTransportNRF24 transport(RADIO_CE_PIN, RADIO_SPI_SS_PIN, RF24_PA_LEVEL_GW);
//MyTransportRFM69 transport;
// Message signing driver (signer needed if MY_SIGNING_FEATURE is turned on in MyConfig.h)
//MySigningNone signer;
//MySigningAtsha204Soft signer;
//MySigningAtsha204 signer;
// Hardware profile
MyHwATMega328 hw;
// Construct MySensors library (signer needed if MY_SIGNING_FEATURE is turned on in MyConfig.h)
MySensor gw(transport, hw /*, signer*/);
EthernetServer server = EthernetServer(TCP_PORT);
EthernetClient *currentClient = NULL;
MyMessage msg;
char convBuf[MAX_PAYLOAD*2+1];
char broker[] PROGMEM = MQTT_BROKER_PREFIX;
bool MQTTClientConnected = false;
uint8_t buffsize;
char buffer[MQTT_MAX_PACKET_SIZE];
volatile uint8_t countRx;
volatile uint8_t countTx;
volatile uint8_t countErr;
void writeEthernet(const char *writeBuffer, uint8_t *writeSize) {
#ifdef TCPDUMP
Serial.print(">>");
char buf[4];
for (uint8_t a=0; a<*writeSize; a++) { sprintf(buf,"%02X ",(uint8_t)writeBuffer[a]); Serial.print(buf); } Serial.println("");
#endif
server.write((const uint8_t *)writeBuffer, *writeSize);
}
void processEthernetMessages() {
char inputString[MQTT_MAX_PACKET_SIZE] = "";
byte inputSize = 0;
byte readCnt = 0;
byte length = 0;
EthernetClient client = server.available();
if (client) {
while (client.available()) {
// Save the current client we are talking with
currentClient = &client;
byte inByte = client.read();
readCnt++;
if (inputSize < MQTT_MAX_PACKET_SIZE) {
inputString[inputSize] = (char)inByte;
inputSize++;
}
if (readCnt == 2) {
length = (inByte & 127) * 1;
}
if (readCnt == (length+2)) {
break;
}
}
#ifdef TCPDUMP
Serial.print("<<");
char buf[4];
for (byte a=0; a<inputSize; a++) { sprintf(buf, "%02X ", (byte)inputString[a]); Serial.print(buf); } Serial.println();
#endif
processMQTTMessage(inputString, inputSize);
currentClient = NULL;
}
}
void incomingMessage(const MyMessage &message) {
rxBlink(1);
sendMQTT(message);
}
void setup()
{
Ethernet.begin(TCP_MAC, TCP_IP);
countRx = 0;
countTx = 0;
countErr = 0;
// Setup led pins
pinMode(RADIO_RX_LED_PIN, OUTPUT);
pinMode(RADIO_TX_LED_PIN, OUTPUT);
pinMode(RADIO_ERROR_LED_PIN, OUTPUT);
digitalWrite(RADIO_RX_LED_PIN, LOW);
digitalWrite(RADIO_TX_LED_PIN, LOW);
digitalWrite(RADIO_ERROR_LED_PIN, LOW);
// Set initial state of leds
digitalWrite(RADIO_RX_LED_PIN, HIGH);
digitalWrite(RADIO_TX_LED_PIN, HIGH);
digitalWrite(RADIO_ERROR_LED_PIN, HIGH);
// Add led timer interrupt
MsTimer2::set(300, ledTimersInterrupt);
MsTimer2::start();
// give the Ethernet interface a second to initialize
delay(1000);
// Initialize gateway at maximum PA level, channel 70 and callback for write operations
gw.begin(incomingMessage, 0, true, 0);
// start listening for clients
server.begin();
Serial.println("Ok!");
}
void loop()
{
gw.process();
processEthernetMessages();
}
inline MyMessage& build (MyMessage &msg, uint8_t destination, uint8_t sensor, uint8_t command, uint8_t type, bool enableAck) {
msg.destination = destination;
msg.sender = GATEWAY_ADDRESS;
msg.sensor = sensor;
msg.type = type;
mSetCommand(msg,command);
mSetRequestAck(msg,enableAck);
mSetAck(msg,false);
return msg;
}
char *getType(char *b, const char **index) {
char *q = b;
char *p = (char *)pgm_read_word(index);
while (*q++ = pgm_read_byte(p++));
*q=0;
return b;
}
void processMQTTMessage(char *inputString, uint8_t inputPos) {
char *str, *p;
uint8_t i = 0;
buffer[0]= 0;
buffsize = 0;
(void)inputPos;
if ((uint8_t)inputString[0] >> 4 == MQTTCONNECT) {
buffer[buffsize++] = MQTTCONNACK << 4;
buffer[buffsize++] = 0x02; // Remaining length
buffer[buffsize++] = 0x00; // Connection accepted
buffer[buffsize++] = 0x00; // Reserved
MQTTClientConnected=true; // We have connection!
}
if ((uint8_t)inputString[0] >> 4 == MQTTPINGREQ) {
buffer[buffsize++] = MQTTPINGRESP << 4;
buffer[buffsize++] = 0x00;
}
if ((uint8_t)inputString[0] >> 4 == MQTTSUBSCRIBE) {
buffer[buffsize++] = MQTTSUBACK << 4; // Just ack everything, we actually dont really care!
buffer[buffsize++] = 0x03; // Remaining length
buffer[buffsize++] = (uint8_t)inputString[2]; // Message ID MSB
buffer[buffsize++] = (uint8_t)inputString[3]; // Message ID LSB
buffer[buffsize++] = MQTTQOS0; // QOS level
}
if ((uint8_t)inputString[0] >> 4 == MQTTUNSUBSCRIBE) {
buffer[buffsize++] = MQTTUNSUBACK << 4;
buffer[buffsize++] = 0x02; // Remaining length
buffer[buffsize++] = (uint8_t)inputString[2]; // Message ID MSB
buffer[buffsize++] = (uint8_t)inputString[3]; // Message ID LSB
}
if ((uint8_t)inputString[0] >> 4 == MQTTDISCONNECT) {
MQTTClientConnected=false; // We lost connection!
}
if (buffsize > 0) {
writeEthernet(buffer,&buffsize);
}
// We publish everything we get, we dont care if its subscribed or not!
if ((uint8_t)inputString[0] >> 4 == MQTTPUBLISH || (MQTT_SEND_SUBSCRIPTION && (uint8_t)inputString[0] >> 4 == MQTTSUBSCRIBE)) {
buffer[0]= 0;
buffsize = 0;
// Cut out address and payload depending on message type.
if ((uint8_t)inputString[0] >> 4 == MQTTSUBSCRIBE) {
strncat(buffer,inputString+6,inputString[5]);
} else {
strncat(buffer,inputString+4,inputString[3]);
}
#ifdef DEBUG
Serial.println(buffer);
#endif
// TODO: Check if we should send ack or not.
for (str = strtok_r(buffer,"/",&p) ; str && i<4 ; str = strtok_r(NULL,"/",&p)) {
if (i == 0) {
if (strcmp_P(str,broker)!=0) { //look for MQTT_BROKER_PREFIX
return; //Message not for us or malformatted!
}
} else if (i==1) {
msg.destination = atoi(str); //NodeID
} else if (i==2) {
msg.sensor = atoi(str); //SensorID
} else if (i==3) {
unsigned char match=255; //SensorType
#ifdef MQTT_TRANSLATE_TYPES
for (uint8_t j=0; strcpy_P(convBuf, (char*)pgm_read_word(&(vType[j]))) ; j++) {
if (strcmp((char*)&str[2],convBuf)==0) { //Strip V_ and compare
match=j;
break;
}
if (j >= V_TOTAL) break;
}
#endif
if ( atoi(str)!=0 || (str[0]=='0' && str[1] =='\0') ) {
match=atoi(str);
}
if (match==255) {
match=V_UNKNOWN;
}
msg.type = match;
}
i++;
} //Check if packge has payload
if ((uint8_t)inputString[1] > (uint8_t)(inputString[3]+2) && !((uint8_t)inputString[0] >> 4 == MQTTSUBSCRIBE)) {
strcpy(convBuf,inputString+(inputString[3]+4));
msg.set(convBuf); //Payload
} else {
msg.set(""); //No payload
}
txBlink(1);
if (!gw.sendRoute(build(msg, msg.destination, msg.sensor, C_SET, msg.type, 0))) errBlink(1);
}
}
void sendMQTT(const MyMessage &inMsg) {
MyMessage msg = inMsg;
buffsize = 0;
if (!MQTTClientConnected) return; //We have no connections - return
if (msg.isAck()) {
// if (msg.sender==255 && mGetCommand(msg)==C_INTERNAL && msg.type==I_ID_REQUEST) {
// TODO: sending ACK request on id_response fucks node up. doesn't work.
// The idea was to confirm id and save to EEPROM_LATEST_NODE_ADDRESS.
// }
} else {
// we have to check every message if its a newly assigned id or not.
// Ack on I_ID_RESPONSE does not work, and checking on C_PRESENTATION isn't reliable.
uint8_t newNodeID = gw.loadState(EEPROM_LATEST_NODE_ADDRESS)+1;
if (newNodeID <= MQTT_FIRST_SENSORID) newNodeID = MQTT_FIRST_SENSORID;
if (msg.sender==newNodeID) {
gw.saveState(EEPROM_LATEST_NODE_ADDRESS,newNodeID);
}
if (mGetCommand(msg)==C_INTERNAL) {
if (msg.type==I_CONFIG) {
txBlink(1);
if (!gw.sendRoute(build(msg, msg.sender, 255, C_INTERNAL, I_CONFIG, 0).set(MQTT_UNIT))) errBlink(1);
return;
} else if (msg.type==I_ID_REQUEST && msg.sender==255) {
uint8_t newNodeID = gw.loadState(EEPROM_LATEST_NODE_ADDRESS)+1;
if (newNodeID <= MQTT_FIRST_SENSORID) newNodeID = MQTT_FIRST_SENSORID;
if (newNodeID >= MQTT_LAST_SENSORID) return; // Sorry no more id's left :(
txBlink(1);
if (!gw.sendRoute(build(msg, msg.sender, 255, C_INTERNAL, I_ID_RESPONSE, 0).set(newNodeID))) errBlink(1);
return;
}
}
if (mGetCommand(msg)!=C_PRESENTATION) {
if (mGetCommand(msg)==C_INTERNAL) msg.type=msg.type+(S_FIRSTCUSTOM-10); //Special message
buffer[buffsize++] = MQTTPUBLISH << 4; // 0:
buffer[buffsize++] = 0x09; // 1: Remaining length with no payload, we'll set this later to correct value, buffsize -2
buffer[buffsize++] = 0x00; // 2: Length MSB (Remaing length can never exceed ff,so MSB must be 0!)
buffer[buffsize++] = 0x08; // 3: Length LSB (ADDR), We'll set this later
strcpy_P(buffer+4, broker);
buffsize+=strlen_P(broker);
#ifdef MQTT_TRANSLATE_TYPES
if (msg.type > V_TOTAL) msg.type=V_UNKNOWN;// If type > defined types set to unknown.
buffsize+=sprintf(&buffer[buffsize],"/%i/%i/V_%s",msg.sender,msg.sensor,getType(convBuf, &vType[msg.type]));
#else
buffsize+=sprintf(&buffer[buffsize],"/%i/%i/%i",msg.sender,msg.sensor,msg.type);
#endif
buffer[3]=buffsize-4; // Set correct address length on byte 4.
#ifdef DEBUG
Serial.println((char*)&buffer[4]);
#endif
msg.getString(convBuf);
for (uint8_t a=0; a<strlen(convBuf); a++) {// Payload
buffer[buffsize++] = convBuf[a];
}
buffer[1]=buffsize-2; // Set correct Remaining length on byte 2.
writeEthernet(buffer,&buffsize);
}
}
}
void ledTimersInterrupt() {
if(countRx && countRx != 255) {
// switch led on
digitalWrite(RADIO_RX_LED_PIN, LOW);
} else if(!countRx) {
// switching off
digitalWrite(RADIO_RX_LED_PIN, HIGH);
}
if(countRx != 255) { countRx--; }
if(countTx && countTx != 255) {
// switch led on
digitalWrite(RADIO_TX_LED_PIN, LOW);
} else if(!countTx) {
// switching off
digitalWrite(RADIO_TX_LED_PIN, HIGH);
}
if(countTx != 255) { countTx--; }
if(countErr && countErr != 255) {
// switch led on
digitalWrite(RADIO_ERROR_LED_PIN, LOW);
} else if(!countErr) {
// switching off
digitalWrite(RADIO_ERROR_LED_PIN, HIGH);
}
if(countErr != 255) { countErr--; }
}
void rxBlink(uint8_t cnt) {
if(countRx == 255) { countRx = cnt; }
}
void txBlink(uint8_t cnt) {
if(countTx == 255) { countTx = cnt; }
}
void errBlink(uint8_t cnt) {
if(countErr == 255) { countErr = cnt; }
}
/**
* The MySensors Arduino library handles the wireless radio link and protocol
* between your home built sensors/actuators and HA controller of choice.
* The sensors forms a self healing radio network with optional repeaters. Each
* repeater and gateway builds a routing tables in EEPROM which keeps track of the
* network topology allowing messages to be routed to nodes.
*
* Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
* Copyright (C) 2013-2015 Sensnology AB
* Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
*
* Documentation: http://www.mysensors.org
* Support Forum: http://forum.mysensors.org
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 2 as published by the Free Software Foundation.
*/
#ifndef MyConfig_h
#define MyConfig_h
#include <stdint.h>
// Enable debug flag for debug prints. This will add a lot to the size of the final sketch but good
// to see what is actually is happening when developing
#define DEBUG
// Disable this line, If you are using TX(1), RX(0) as normal I/O pin
#define ENABLED_SERIAL
// Serial output baud rate (for debug prints and serial gateway)
#define BAUD_RATE 115200
/**********************************
* Over the air firmware updates
***********************************/
// The following define enables the safe over-the-air firmware update feature
// which requires external flash and the DualOptiBoot bootloader.
// Note: You can still have OTA FW updates without external flash but it
// requires the MYSBootloader and disabled MY_OTA_FIRMWARE_FEATURE
//#define MY_OTA_FIRMWARE_FEATURE
// Slave select pin for external flash
#define MY_OTA_FLASH_SS 8
// Flash jdecid
#define MY_OTA_FLASH_JDECID 0x1F65
/**********************************
* Information LEDs blinking
***********************************/
// This feature enables LEDs blinking on message receive, transmit
// or if some error occured. This was commonly used only in gateways,
// but now can be used in any sensor node. Also the LEDs can now be
// disabled in the gateway.
// #define WITH_LEDS_BLINKING
// The following setting allows you to inverse the blinking feature WITH_LEDS_BLINKING
// When WITH_LEDS_BLINKING_INVERSE is enabled LEDSs are normally turned on and switches
// off when blinking
//#define WITH_LEDS_BLINKING_INVERSE
// default LEDs blinking period in milliseconds
#define DEFAULT_LED_BLINK_PERIOD 300
// The RX LED default pin
#define DEFAULT_RX_LED_PIN 6
// The TX LED default pin
#define DEFAULT_TX_LED_PIN 5
// The Error LED default pin
#define DEFAULT_ERR_LED_PIN 4
/**********************************
* Message Signing Settings
***********************************/
// Disable to completly disable signing functionality in library
//#define MY_SIGNING_FEATURE
// Define a suitable timeout for a signature verification session
// Consider the turnaround from a nonce being generated to a signed message being received
// which might vary, especially in networks with many hops. 5s ought to be enough for anyone.
#define MY_VERIFICATION_TIMEOUT_MS 5000
// Enable to turn on whitelisting
// When enabled, a signing node will salt the signature with it's unique signature and nodeId.
// The verifying node will look up the sender in a local table of trusted nodes and
// do the corresponding salting in order to verify the signature.
// For this reason, if whitelisting is enabled on one of the nodes in a sign-verify pair, both
// nodes have to implement whitelisting for this to work.
// Note that a node can still transmit a non-salted message (i.e. have whitelisting disabled)
// to a node that has whitelisting enabled (assuming the receiver does not have a matching entry
// for the sender in it's whitelist)
//#define MY_SECURE_NODE_WHITELISTING
// MySigningAtsha204 default setting
#define MY_ATSHA204_PIN 17 // A3 - pin where ATSHA204 is attached
// MySigningAtsha204Soft default settings
#define MY_RANDOMSEED_PIN 7 // A7 - Pin used for random generation (do not connect anything to this)
// Key to use for HMAC calculation in MySigningAtsha204Soft (32 bytes)
#define MY_HMAC_KEY 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
/**********************************
* NRF24L01 Driver Defaults
***********************************/
#define RF24_CE_PIN 9
#define RF24_CS_PIN 10
#define RF24_PA_LEVEL RF24_PA_MAX
#define RF24_PA_LEVEL_GW RF24_PA_LOW
// RF channel for the sensor net, 0-127
#define RF24_CHANNEL 76
//RF24_250KBPS for 250kbs, RF24_1MBPS for 1Mbps, or RF24_2MBPS for 2Mbps
#define RF24_DATARATE RF24_250KBPS
// This is also act as base value for sensor nodeId addresses. Change this (or channel) if you have more than one sensor network.
#define RF24_BASE_RADIO_ID ((uint64_t)0xA8A8E1FC00LL)
// Enable SOFTSPI for NRF24L01 when using the W5100 Ethernet module
//#define SOFTSPI
#ifdef SOFTSPI
// Define the soft SPI pins used for NRF radio
const uint8_t SOFT_SPI_MISO_PIN = 16;
const uint8_t SOFT_SPI_MOSI_PIN = 15;
const uint8_t SOFT_SPI_SCK_PIN = 14;
#endif
/**********************************
* RFM69 Driver Defaults
***********************************/
// Default network id. Use the same for all nodes that will talk to each other
#define RFM69_NETWORKID 100
// Default frequency to use. This must match the hardware version of the RFM69 radio (uncomment one):
// #define RFM69_FREQUENCY RF69_433MHZ
#define RFM69_FREQUENCY RF69_868MHZ
//#define FREQUENCY RF69_915MHZ
// Enable this for encryption of packets
//#define RFM69_ENABLE_ENCRYPTION
#define RFM69_ENCRYPTKEY "sampleEncryptKey" //exactly the same 16 characters/bytes on all nodes!
#endif
/*
The MySensors library adds a new layer on top of the RF24 library.
It handles radio network routing, relaying and ids.
Created by Henrik Ekblad <henrik.ekblad@gmail.com>
Modified by Daniel Wiegert
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
version 2 as published by the Free Software Foundation.
*/
#ifdef DEBUG
#define TCPDUMP // Dump TCP packages
#endif
#define MQTT_FIRST_SENSORID 20 // If you want manually configured nodes below this value. 255 = Disable
#define MQTT_LAST_SENSORID 254 // 254 is max! 255 reserved.
#define MQTT_BROKER_PREFIX "MyMQTT" // First prefix in MQTT tree, keep short!
#define MQTT_SEND_SUBSCRIPTION 1 // Send empty payload (request) to node upon MQTT client subscribe request.
// NOTE above : Beware to check if there is any length on payload in your incommingMessage code:
// Example: if (msg.type==V_LIGHT && strlen(msg.getString())>0) otherwise the code might do strange things.
#define MQTT_UNIT "M" // Select M for metric or I for imperial.
#define MQTT_TRANSLATE_TYPES // V_TYPE in address, Comment if you want all numbers (MyMQTT/01/01/01)
//////////////////////////////////////////////////////////////////
#define EEPROM_LATEST_NODE_ADDRESS ((uint8_t)EEPROM_LOCAL_CONFIG_ADDRESS)
#define MQTT_MAX_PACKET_SIZE 100
#define MQTTPROTOCOLVERSION 3
#define MQTTCONNECT 1 // Client request to connect to Server
#define MQTTCONNACK 2 // Connect Acknowledgment
#define MQTTPUBLISH 3 // Publish message
#define MQTTPUBACK 4 // Publish Acknowledgment
#define MQTTPUBREC 5 // Publish Received (assured delivery part 1)
#define MQTTPUBREL 6 // Publish Release (assured delivery part 2)
#define MQTTPUBCOMP 7 // Publish Complete (assured delivery part 3)
#define MQTTSUBSCRIBE 8 // Client Subscribe request
#define MQTTSUBACK 9 // Subscribe Acknowledgment
#define MQTTUNSUBSCRIBE 10 // Client Unsubscribe request
#define MQTTUNSUBACK 11 // Unsubscribe Acknowledgment
#define MQTTPINGREQ 12 // PING Request
#define MQTTPINGRESP 13 // PING Response
#define MQTTDISCONNECT 14 // Client is Disconnecting
#define MQTTReserved 15 // Reserved
#define MQTTQOS0 (0 << 1)
#define MQTTQOS1 (1 << 1)
#define MQTTQOS2 (2 << 1)
#ifdef MQTT_TRANSLATE_TYPES
char V_0[] PROGMEM = "TEMP"; //V_TEMP
char V_1[] PROGMEM = "HUM"; //V_HUM
char V_2[] PROGMEM = "LIGHT"; //V_LIGHT
char V_3[] PROGMEM = "DIMMER"; //V_DIMMER
char V_4[] PROGMEM = "PRESSURE"; //V_PRESSURE
char V_5[] PROGMEM = "FORECAST"; //V_FORECAST
char V_6[] PROGMEM = "RAIN"; //V_RAIN
char V_7[] PROGMEM = "RAINRATE"; //V_RAINRATE
char V_8[] PROGMEM = "WIND"; //V_WIND
char V_9[] PROGMEM = "GUST"; //V_GUST
char V_10[] PROGMEM = "DIRECTON"; //V_DIRECTON
char V_11[] PROGMEM = "UV"; //V_UV
char V_12[] PROGMEM = "WEIGHT"; //V_WEIGHT
char V_13[] PROGMEM = "DISTANCE"; //V_DISTANCE
char V_14[] PROGMEM = "IMPEDANCE"; //V_IMPEDANCE
char V_15[] PROGMEM = "ARMED"; //V_ARMED
char V_16[] PROGMEM = "TRIPPED"; //V_TRIPPED
char V_17[] PROGMEM = "WATT"; //V_WATT
char V_18[] PROGMEM = "KWH"; //V_KWH
char V_19[] PROGMEM = "SCENE_ON"; //V_SCENE_ON
char V_20[] PROGMEM = "SCENE_OFF"; //V_SCENE_OFF
char V_21[] PROGMEM = "HEATER"; //V_HEATER
char V_22[] PROGMEM = "HEATER_SW"; //V_HEATER_SW
char V_23[] PROGMEM = "LIGHT_LEVEL"; //V_LIGHT_LEVEL
char V_24[] PROGMEM = "VAR1"; //V_VAR1
char V_25[] PROGMEM = "VAR2"; //V_VAR2
char V_26[] PROGMEM = "VAR3"; //V_VAR3
char V_27[] PROGMEM = "VAR4"; //V_VAR4
char V_28[] PROGMEM = "VAR5"; //V_VAR5
char V_29[] PROGMEM = "UP"; //V_UP
char V_30[] PROGMEM = "DOWN"; //V_DOWN
char V_31[] PROGMEM = "STOP"; //V_STOP
char V_32[] PROGMEM = "IR_SEND"; //V_IR_SEND
char V_33[] PROGMEM = "IR_RECEIVE"; //V_IR_RECEIVE
char V_34[] PROGMEM = "FLOW"; //V_FLOW
char V_35[] PROGMEM = "VOLUME"; //V_VOLUME
char V_36[] PROGMEM = "LOCK_STATUS"; //V_LOCK_STATUS
char V_37[] PROGMEM = "DUST_LEVEL"; //V_DUST_LEVEL
char V_38[] PROGMEM = "VOLTAGE"; //V_VOLTAGE
char V_39[] PROGMEM = "CURRENT"; //V_CURRENT
char V_40[] PROGMEM = ""; //
char V_41[] PROGMEM = ""; //
char V_42[] PROGMEM = ""; //
char V_43[] PROGMEM = ""; //
char V_44[] PROGMEM = ""; //
char V_45[] PROGMEM = ""; //
char V_46[] PROGMEM = ""; //
char V_47[] PROGMEM = ""; //
char V_48[] PROGMEM = ""; //
char V_49[] PROGMEM = ""; //
char V_50[] PROGMEM = ""; //
char V_51[] PROGMEM = ""; //
char V_52[] PROGMEM = ""; //
char V_53[] PROGMEM = ""; //
char V_54[] PROGMEM = ""; //
char V_55[] PROGMEM = ""; //
char V_56[] PROGMEM = ""; //
char V_57[] PROGMEM = ""; //
char V_58[] PROGMEM = ""; //
char V_59[] PROGMEM = ""; //
char V_60[] PROGMEM = "DEFAULT"; //Custom for MQTTGateway
char V_61[] PROGMEM = "SKETCH_NAME"; //Custom for MQTTGateway
char V_62[] PROGMEM = "SKETCH_VERSION"; //Custom for MQTTGateway
char V_63[] PROGMEM = "UNKNOWN"; //Custom for MQTTGateway
//////////////////////////////////////////////////////////////////
PROGMEM const char *vType[] = {
V_0, V_1, V_2, V_3, V_4, V_5, V_6, V_7, V_8, V_9, V_10,
V_11, V_12, V_13, V_14, V_15, V_16, V_17, V_18, V_19, V_20,
V_21, V_22, V_23, V_24, V_25, V_26, V_27, V_28, V_29, V_30,
V_31, V_32, V_33, V_34, V_35, V_36, V_37, V_38, V_39, V_40,
V_41, V_42, V_43, V_44, V_45, V_46, V_47, V_48, V_49, V_50,
V_51, V_52, V_53, V_54, V_55, V_56, V_57, V_58, V_59, V_60,
V_61, V_62, V_63
};
#define S_FIRSTCUSTOM 60
#define V_TOTAL (sizeof(vType)/sizeof(char *))-1
#endif
#define S_FIRSTCUSTOM 60
#define V_UNKNOWN 63
root@cs670:/etc/openhab/configurations# tail openhab.cfg
############################### MySensors Binding ####################################
#
# Serial Port Configuration
#mysensors:port=/dev/ttyMySensorsGateway
# MQTT MySensors Binding
mqtt.mysensor.url=tcp://10.0.1.79:1883
mqtt.mysensor.clientId=MQTT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment