Capabilities embryo, misc fixes
Call sketch setup() before presentation() Bugfix in RFIDLockSensor Disable remote reset option Topic comparison bugix MQTT gateway
This commit is contained in:
@@ -48,6 +48,8 @@
|
||||
#define MY_BAUD_RATE 115200
|
||||
#endif
|
||||
|
||||
// Disables over-the-air reset of node
|
||||
//#define MY_DISABLE_REMOTE_RESET
|
||||
|
||||
/**********************************
|
||||
* Radio selection and node config
|
||||
|
||||
@@ -200,19 +200,10 @@
|
||||
#endif
|
||||
|
||||
|
||||
#include "core/MyCapabilities.h"
|
||||
#include "core/MyMessage.cpp"
|
||||
#include "core/MySensorCore.cpp"
|
||||
|
||||
extern void setup();
|
||||
// Optional sketch functions called by MySensors library
|
||||
void receive(const MyMessage &message) __attribute__((weak));
|
||||
void receiveTime(unsigned long) __attribute__((weak));
|
||||
void presentation() __attribute__((weak));
|
||||
extern "C" void setup() __attribute__((weak));
|
||||
extern "C" void loop() __attribute__((weak));
|
||||
extern "C" void loop2() __attribute__((weak));
|
||||
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
#if defined(MY_GATEWAY_ESP8266)
|
||||
|
||||
@@ -71,7 +71,7 @@ void incomingMQTT(char* topic, byte* payload,
|
||||
switch (i) {
|
||||
case 0: {
|
||||
// Topic prefix
|
||||
if (strcmp_P(str, MY_MQTT_SUBSCRIBE_TOPIC_PREFIX) != 0) {
|
||||
if (strcmp(str, MY_MQTT_SUBSCRIBE_TOPIC_PREFIX) != 0) {
|
||||
// Message not for us or malformed!
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
// Initialize library and handle sketch functions like we want to
|
||||
|
||||
int main(void) {
|
||||
init();
|
||||
#if defined(USBCON)
|
||||
USBDevice.attach();
|
||||
#endif
|
||||
_begin(); // Startup MySensors library
|
||||
if (setup) setup(); // Call sketch setup
|
||||
|
||||
for(;;) {
|
||||
_process(); // Process incoming data
|
||||
|
||||
@@ -83,7 +83,6 @@ static void loop_wrapper() {
|
||||
static bool setup_done = false;
|
||||
if(!setup_done) {
|
||||
_begin(); // Startup MySensors library
|
||||
setup();
|
||||
setup_done = true;
|
||||
}
|
||||
preloop_update_frequency();
|
||||
|
||||
@@ -64,7 +64,7 @@ void _begin() {
|
||||
hwInit();
|
||||
#endif
|
||||
|
||||
debug(PSTR("Starting " MY_NODE_TYPE " (" LIBRARY_VERSION ")\n"));
|
||||
debug(PSTR("Starting " MY_NODE_TYPE " (" MY_CAPABILIIES ", " LIBRARY_VERSION ")\n"));
|
||||
|
||||
#if defined(MY_RADIO_FEATURE)
|
||||
_failedTransmissions = 0;
|
||||
@@ -157,6 +157,11 @@ void _begin() {
|
||||
}
|
||||
#endif
|
||||
|
||||
// Call sketch setup
|
||||
if (setup)
|
||||
setup();
|
||||
|
||||
|
||||
#if defined(MY_RADIO_FEATURE)
|
||||
transportPresentNode();
|
||||
#endif
|
||||
@@ -235,26 +240,31 @@ void _processInternalMessages() {
|
||||
bool isMetric;
|
||||
uint8_t type = _msg.type;
|
||||
|
||||
if (type == I_REBOOT) {
|
||||
// Requires MySensors or other bootloader with watchdogs enabled
|
||||
hwReboot();
|
||||
} else if (type == I_CONFIG) {
|
||||
#if !defined(MY_DISABLE_REMOTE_RESET)
|
||||
if (type == I_REBOOT) {
|
||||
// Requires MySensors or other bootloader with watchdogs enabled
|
||||
hwReboot();
|
||||
} else
|
||||
#endif
|
||||
if (type == I_CONFIG) {
|
||||
// Pick up configuration from controller (currently only metric/imperial)
|
||||
// and store it in eeprom if changed
|
||||
if (_msg.getString() == NULL) {
|
||||
isMetric = true;
|
||||
} else {
|
||||
isMetric = _msg.getString()[0] == 'M' ;
|
||||
}
|
||||
isMetric = true;
|
||||
} else {
|
||||
isMetric = _msg.getString()[0] == 'M';
|
||||
}
|
||||
_cc.isMetric = isMetric;
|
||||
hwWriteConfig(EEPROM_CONTROLLER_CONFIG_ADDRESS, isMetric);
|
||||
} else if (type == I_PRESENTATION) {
|
||||
// Re-send node presentation to controller
|
||||
#if defined(MY_RADIO_FEATURE)
|
||||
transportPresentNode();
|
||||
#endif
|
||||
if (presentation)
|
||||
presentation();
|
||||
if (!mGetAck(_msg)) {
|
||||
// Re-send node presentation to controller
|
||||
#if defined(MY_RADIO_FEATURE)
|
||||
transportPresentNode();
|
||||
#endif
|
||||
if (presentation)
|
||||
presentation();
|
||||
}
|
||||
} else if (type == I_HEARTBEAT) {
|
||||
if (!mGetAck(_msg)) {
|
||||
// Send heartbeat ack message back to sender (with the same payload)
|
||||
@@ -267,7 +277,8 @@ void _processInternalMessages() {
|
||||
}
|
||||
} else if (type == I_TIME && receiveTime) {
|
||||
// Deliver time to callback
|
||||
receiveTime(_msg.getULong());
|
||||
if (receiveTime)
|
||||
receiveTime(_msg.getULong());
|
||||
}
|
||||
#if defined(MY_REPEATER_FEATURE)
|
||||
if (type == I_CHILDREN && _msg.getString()[0] == 'C') {
|
||||
|
||||
@@ -229,6 +229,9 @@ extern MyMessage _msgTmp; // Buffer for temporary messages (acks and nonces amo
|
||||
void receive(const MyMessage &message) __attribute__((weak));
|
||||
void receiveTime(unsigned long) __attribute__((weak));
|
||||
void presentation() __attribute__((weak));
|
||||
void setup() __attribute__((weak));
|
||||
void loop() __attribute__((weak));
|
||||
|
||||
|
||||
// Inline function and macros
|
||||
static inline MyMessage& build(MyMessage &msg, uint8_t sender, uint8_t destination, uint8_t sensor, uint8_t command, uint8_t type, bool enableAck) {
|
||||
|
||||
@@ -135,7 +135,7 @@ void loop() {
|
||||
boolean valid = false;
|
||||
// Compare this key to the valid once registered here in sketch
|
||||
for (int i=0;i<keyCount && !valid;i++) {
|
||||
for (int j=0;i<currentKeyLength && !valid;j++) {
|
||||
for (int j=0;j<currentKeyLength && !valid;j++) {
|
||||
if (key[j] != validKeys[i][j]) {
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
{
|
||||
for (int sensor=1, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS;sensor++, pin++) {
|
||||
// Then set relay pins in output mode
|
||||
pinMode(pin, OUTPUT);
|
||||
|
||||
Reference in New Issue
Block a user