Merge pull request #270 from mysensors/capabilities-embryo-and-mixed-fixes
Capabilities embryo, misc fixes
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)
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
/**
|
||||
* 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 Tomas Hozza <thozza@gmail.com>
|
||||
* Copyright (C) 2015 Tomas Hozza
|
||||
* 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 MyCapabilities_h
|
||||
#define MyCapabilities_h
|
||||
|
||||
#if defined(MY_DISABLE_REMOTE_RESET)
|
||||
#define MY_CAP_RESET "N"
|
||||
#else
|
||||
#define MY_CAP_RESET "R"
|
||||
#endif
|
||||
|
||||
#if defined(MY_OTA_FIRMWARE_FEATURE)
|
||||
#define MY_CAP_OTA_FW "O"
|
||||
#else
|
||||
#define MY_CAP_OTA_FW "N"
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(MY_RADIO_NRF24)
|
||||
#define MY_CAP_RADIO "N"
|
||||
#elif defined(MY_RADIO_RFM69)
|
||||
#define MY_CAP_RADIO "R"
|
||||
#elif defined(MY_RS485)
|
||||
#define MY_CAP_RADIO "S"
|
||||
#else
|
||||
#define MY_CAP_RADIO "?"
|
||||
#endif
|
||||
|
||||
#if defined(MY_GATEWAY_FEATURE)
|
||||
#define MY_CAP_TYPE "G"
|
||||
#elif defined(MY_REPEATER_FEATURE)
|
||||
#define MY_CAP_TYPE "R"
|
||||
#else
|
||||
#define MY_CAP_TYPE "N"
|
||||
#endif
|
||||
|
||||
#if defined(ARDUINO_ARCH_SAMD)
|
||||
#define MY_CAP_ARCH "S"
|
||||
#elif defined(ARDUINO_ARCH_ESP8266)
|
||||
#define MY_CAP_ARCH "E"
|
||||
#elif defined(ARDUINO_ARCH_AVR)
|
||||
#define MY_CAP_ARCH "A"
|
||||
#else
|
||||
#define MY_CAP_ARCH "?"
|
||||
#endif
|
||||
|
||||
#if defined(MY_SIGNING_ATSHA204)
|
||||
#define MY_CAP_SIGN "A"
|
||||
#elif defined(MY_SIGNING_SOFT)
|
||||
#define MY_CAP_SIGN "S"
|
||||
#else
|
||||
#define MY_CAP_SIGN "?"
|
||||
#endif
|
||||
|
||||
|
||||
#define MY_CAPABILIIES MY_CAP_RESET MY_CAP_OTA_FW MY_CAP_TYPE MY_CAP_ARCH MY_CAP_SIGN
|
||||
|
||||
#endif /* MyGatewayTransportEthernet_h */
|
||||
@@ -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