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:
Henrik Ekblad
2015-11-28 12:03:43 +01:00
parent 8e2c8cb420
commit 230d698bfd
9 changed files with 37 additions and 31 deletions
+2
View File
@@ -48,6 +48,8 @@
#define MY_BAUD_RATE 115200 #define MY_BAUD_RATE 115200
#endif #endif
// Disables over-the-air reset of node
//#define MY_DISABLE_REMOTE_RESET
/********************************** /**********************************
* Radio selection and node config * Radio selection and node config
+1 -10
View File
@@ -200,19 +200,10 @@
#endif #endif
#include "core/MyCapabilities.h"
#include "core/MyMessage.cpp" #include "core/MyMessage.cpp"
#include "core/MySensorCore.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> #include <Arduino.h>
#if defined(MY_GATEWAY_ESP8266) #if defined(MY_GATEWAY_ESP8266)
@@ -71,7 +71,7 @@ void incomingMQTT(char* topic, byte* payload,
switch (i) { switch (i) {
case 0: { case 0: {
// Topic prefix // 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! // Message not for us or malformed!
return; return;
} }
+1 -1
View File
@@ -1,11 +1,11 @@
// Initialize library and handle sketch functions like we want to // Initialize library and handle sketch functions like we want to
int main(void) { int main(void) {
init(); init();
#if defined(USBCON) #if defined(USBCON)
USBDevice.attach(); USBDevice.attach();
#endif #endif
_begin(); // Startup MySensors library _begin(); // Startup MySensors library
if (setup) setup(); // Call sketch setup
for(;;) { for(;;) {
_process(); // Process incoming data _process(); // Process incoming data
@@ -83,7 +83,6 @@ static void loop_wrapper() {
static bool setup_done = false; static bool setup_done = false;
if(!setup_done) { if(!setup_done) {
_begin(); // Startup MySensors library _begin(); // Startup MySensors library
setup();
setup_done = true; setup_done = true;
} }
preloop_update_frequency(); preloop_update_frequency();
+27 -16
View File
@@ -64,7 +64,7 @@ void _begin() {
hwInit(); hwInit();
#endif #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) #if defined(MY_RADIO_FEATURE)
_failedTransmissions = 0; _failedTransmissions = 0;
@@ -157,6 +157,11 @@ void _begin() {
} }
#endif #endif
// Call sketch setup
if (setup)
setup();
#if defined(MY_RADIO_FEATURE) #if defined(MY_RADIO_FEATURE)
transportPresentNode(); transportPresentNode();
#endif #endif
@@ -235,26 +240,31 @@ void _processInternalMessages() {
bool isMetric; bool isMetric;
uint8_t type = _msg.type; uint8_t type = _msg.type;
if (type == I_REBOOT) { #if !defined(MY_DISABLE_REMOTE_RESET)
// Requires MySensors or other bootloader with watchdogs enabled if (type == I_REBOOT) {
hwReboot(); // Requires MySensors or other bootloader with watchdogs enabled
} else if (type == I_CONFIG) { hwReboot();
} else
#endif
if (type == I_CONFIG) {
// Pick up configuration from controller (currently only metric/imperial) // Pick up configuration from controller (currently only metric/imperial)
// and store it in eeprom if changed // and store it in eeprom if changed
if (_msg.getString() == NULL) { if (_msg.getString() == NULL) {
isMetric = true; isMetric = true;
} else { } else {
isMetric = _msg.getString()[0] == 'M' ; isMetric = _msg.getString()[0] == 'M';
} }
_cc.isMetric = isMetric; _cc.isMetric = isMetric;
hwWriteConfig(EEPROM_CONTROLLER_CONFIG_ADDRESS, isMetric); hwWriteConfig(EEPROM_CONTROLLER_CONFIG_ADDRESS, isMetric);
} else if (type == I_PRESENTATION) { } else if (type == I_PRESENTATION) {
// Re-send node presentation to controller if (!mGetAck(_msg)) {
#if defined(MY_RADIO_FEATURE) // Re-send node presentation to controller
transportPresentNode(); #if defined(MY_RADIO_FEATURE)
#endif transportPresentNode();
if (presentation) #endif
presentation(); if (presentation)
presentation();
}
} else if (type == I_HEARTBEAT) { } else if (type == I_HEARTBEAT) {
if (!mGetAck(_msg)) { if (!mGetAck(_msg)) {
// Send heartbeat ack message back to sender (with the same payload) // Send heartbeat ack message back to sender (with the same payload)
@@ -267,7 +277,8 @@ void _processInternalMessages() {
} }
} else if (type == I_TIME && receiveTime) { } else if (type == I_TIME && receiveTime) {
// Deliver time to callback // Deliver time to callback
receiveTime(_msg.getULong()); if (receiveTime)
receiveTime(_msg.getULong());
} }
#if defined(MY_REPEATER_FEATURE) #if defined(MY_REPEATER_FEATURE)
if (type == I_CHILDREN && _msg.getString()[0] == 'C') { if (type == I_CHILDREN && _msg.getString()[0] == 'C') {
+3
View File
@@ -229,6 +229,9 @@ extern MyMessage _msgTmp; // Buffer for temporary messages (acks and nonces amo
void receive(const MyMessage &message) __attribute__((weak)); void receive(const MyMessage &message) __attribute__((weak));
void receiveTime(unsigned long) __attribute__((weak)); void receiveTime(unsigned long) __attribute__((weak));
void presentation() __attribute__((weak)); void presentation() __attribute__((weak));
void setup() __attribute__((weak));
void loop() __attribute__((weak));
// Inline function and macros // 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) { 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; boolean valid = false;
// Compare this key to the valid once registered here in sketch // Compare this key to the valid once registered here in sketch
for (int i=0;i<keyCount && !valid;i++) { 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]) { if (key[j] != validKeys[i][j]) {
break; break;
} }
@@ -47,7 +47,7 @@
void setup() void setup()
{ {
for (int sensor=1, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS;sensor++, pin++) { for (int sensor=1, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS;sensor++, pin++) {
// Then set relay pins in output mode // Then set relay pins in output mode
pinMode(pin, OUTPUT); pinMode(pin, OUTPUT);