@@ -17,6 +17,8 @@
|
|||||||
* version 2 as published by the Free Software Foundation.
|
* version 2 as published by the Free Software Foundation.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifdef ARDUINO_ARCH_AVR
|
||||||
|
|
||||||
#include "MyHw.h"
|
#include "MyHw.h"
|
||||||
#include "MyHwATMega328.h"
|
#include "MyHwATMega328.h"
|
||||||
|
|
||||||
@@ -215,3 +217,4 @@ void MyHwATMega328::debugPrint(bool isGW, const char *fmt, ... ) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#endif // #ifdef ARDUINO_ARCH_AVR
|
||||||
|
|||||||
@@ -20,6 +20,8 @@
|
|||||||
#ifndef MyHwATMega328_h
|
#ifndef MyHwATMega328_h
|
||||||
#define MyHwATMega328_h
|
#define MyHwATMega328_h
|
||||||
|
|
||||||
|
#ifdef ARDUINO_ARCH_AVR
|
||||||
|
|
||||||
#include "MyHw.h"
|
#include "MyHw.h"
|
||||||
#include "MyConfig.h"
|
#include "MyConfig.h"
|
||||||
#include "MyMessage.h"
|
#include "MyMessage.h"
|
||||||
@@ -116,3 +118,4 @@ private:
|
|||||||
void internalSleep(unsigned long ms);
|
void internalSleep(unsigned long ms);
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
#endif // #ifdef ARDUINO_ARCH_AVR
|
||||||
|
|||||||
@@ -0,0 +1,184 @@
|
|||||||
|
/**
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef ARDUINO_ARCH_ESP8266
|
||||||
|
|
||||||
|
#include "MyHw.h"
|
||||||
|
#include "MyHwESP8266.h"
|
||||||
|
#include <EEPROM.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
int8_t pinIntTrigger = 0;
|
||||||
|
void wakeUp() //place to send the interrupts
|
||||||
|
{
|
||||||
|
pinIntTrigger = 1;
|
||||||
|
}
|
||||||
|
void wakeUp2() //place to send the second interrupts
|
||||||
|
{
|
||||||
|
pinIntTrigger = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Watchdog Timer interrupt service routine. This routine is required
|
||||||
|
// to allow automatic WDIF and WDIE bit clearance in hardware.
|
||||||
|
ISR (WDT_vect)
|
||||||
|
{
|
||||||
|
// WDIE & WDIF is cleared in hardware upon entering this ISR
|
||||||
|
wdt_disable();
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
static void hw_initConfigBlock( size_t length = 1024 /*ATMega328 has 1024 bytes*/ )
|
||||||
|
{
|
||||||
|
static bool initDone = false;
|
||||||
|
if (!initDone)
|
||||||
|
{
|
||||||
|
EEPROM.begin(length);
|
||||||
|
initDone = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void hw_readConfigBlock(void* buf, void* adr, size_t length)
|
||||||
|
{
|
||||||
|
hw_initConfigBlock();
|
||||||
|
uint8_t* dst = static_cast<uint8_t*>(buf);
|
||||||
|
int offs = reinterpret_cast<int>(adr);
|
||||||
|
while (length-- > 0)
|
||||||
|
{
|
||||||
|
*dst++ = EEPROM.read(offs++);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void hw_writeConfigBlock(void* buf, void* adr, size_t length)
|
||||||
|
{
|
||||||
|
hw_initConfigBlock();
|
||||||
|
uint8_t* src = static_cast<uint8_t*>(buf);
|
||||||
|
int offs = reinterpret_cast<int>(adr);
|
||||||
|
while (length-- > 0)
|
||||||
|
{
|
||||||
|
EEPROM.write(offs++, *src++);
|
||||||
|
}
|
||||||
|
EEPROM.commit();
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t hw_readConfig(int adr)
|
||||||
|
{
|
||||||
|
uint8_t value;
|
||||||
|
hw_readConfigBlock(&value, reinterpret_cast<void*>(adr), 1);
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
void hw_writeConfig(int adr, uint8_t value)
|
||||||
|
{
|
||||||
|
uint8_t curr = hw_readConfig(adr);
|
||||||
|
if (curr != value)
|
||||||
|
{
|
||||||
|
hw_writeConfigBlock(&value, reinterpret_cast<void*>(adr), 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
MyHwESP8266::MyHwESP8266() : MyHw()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
// The following was redifined as macros to save space
|
||||||
|
|
||||||
|
inline uint8_t MyHwATMega328::readConfig(uint8_t pos) {
|
||||||
|
return eeprom_read_byte((uint8_t*)pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void MyHwATMega328::writeConfig(uint8_t pos, uint8_t value) {
|
||||||
|
eeprom_update_byte((uint8_t*)pos, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void MyHwATMega328::readConfigBlock(void* buf, void * pos, size_t length) {
|
||||||
|
eeprom_read_block(buf, (void*)pos, length);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void MyHwATMega328::writeConfigBlock(void* pos, void* buf, size_t length) {
|
||||||
|
eeprom_write_block((void*)pos, (void*)buf, length);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline void MyHwATMega328::init() {
|
||||||
|
Serial.begin(BAUD_RATE);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void MyHwATMega328::watchdogReset() {
|
||||||
|
wdt_reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void MyHwATMega328::reboot() {
|
||||||
|
wdt_enable(WDTO_15MS); for (;;);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline unsigned long MyHwATMega328::millis() {
|
||||||
|
return ::millis();
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
void MyHwESP8266::sleep(unsigned long ms) {
|
||||||
|
// TODO: Not supported!
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MyHwESP8266::sleep(uint8_t interrupt, uint8_t mode, unsigned long ms) {
|
||||||
|
// TODO: Not supported!
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline uint8_t MyHwESP8266::sleep(uint8_t interrupt1, uint8_t mode1, uint8_t interrupt2, uint8_t mode2, unsigned long ms) {
|
||||||
|
// TODO: Not supported!
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
|
void MyHwESP8266::debugPrint(bool isGW, const char *fmt, ... ) {
|
||||||
|
char fmtBuffer[300];
|
||||||
|
if (isGW) {
|
||||||
|
// prepend debug message to be handled correctly by controller (C_INTERNAL, I_LOG_MESSAGE)
|
||||||
|
snprintf_P(fmtBuffer, 299, PSTR("0;0;%d;0;%d;"), C_INTERNAL, I_LOG_MESSAGE);
|
||||||
|
Serial.print(fmtBuffer);
|
||||||
|
}
|
||||||
|
va_list args;
|
||||||
|
va_start (args, fmt );
|
||||||
|
va_end (args);
|
||||||
|
if (isGW) {
|
||||||
|
// Truncate message if this is gateway node
|
||||||
|
vsnprintf_P(fmtBuffer, 60, fmt, args);
|
||||||
|
fmtBuffer[59] = '\n';
|
||||||
|
fmtBuffer[60] = '\0';
|
||||||
|
} else {
|
||||||
|
vsnprintf_P(fmtBuffer, 299, fmt, args);
|
||||||
|
}
|
||||||
|
va_end (args);
|
||||||
|
Serial.print(fmtBuffer);
|
||||||
|
Serial.flush();
|
||||||
|
|
||||||
|
//Serial.write(freeRam());
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // #ifdef ARDUINO_ARCH_ESP8266
|
||||||
@@ -0,0 +1,86 @@
|
|||||||
|
/**
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef ARDUINO_ARCH_ESP8266
|
||||||
|
|
||||||
|
#ifndef MyHwESP8266_h
|
||||||
|
#define MyHwESP8266_h
|
||||||
|
|
||||||
|
#include "MyHw.h"
|
||||||
|
#include "MyConfig.h"
|
||||||
|
#include "MyMessage.h"
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
#include <Arduino.h>
|
||||||
|
#include <SPI.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Define these as macros to save valuable space
|
||||||
|
|
||||||
|
#define hw_digitalWrite(__pin, __value) (digitalWrite(__pin, __value))
|
||||||
|
#define hw_init() Serial.begin(BAUD_RATE)
|
||||||
|
#define hw_watchdogReset() wdt_reset()
|
||||||
|
#define hw_reboot() wdt_enable(WDTO_15MS); while (1)
|
||||||
|
#define hw_millis() millis()
|
||||||
|
|
||||||
|
void hw_readConfigBlock(void* buf, void* adr, size_t length);
|
||||||
|
void hw_writeConfigBlock(void* buf, void* adr, size_t length);
|
||||||
|
void hw_writeConfig(int adr, uint8_t value);
|
||||||
|
uint8_t hw_readConfig(int adr);
|
||||||
|
|
||||||
|
enum period_t
|
||||||
|
{
|
||||||
|
SLEEP_15Ms,
|
||||||
|
SLEEP_30MS,
|
||||||
|
SLEEP_60MS,
|
||||||
|
SLEEP_120MS,
|
||||||
|
SLEEP_250MS,
|
||||||
|
SLEEP_500MS,
|
||||||
|
SLEEP_1S,
|
||||||
|
SLEEP_2S,
|
||||||
|
SLEEP_4S,
|
||||||
|
SLEEP_8S,
|
||||||
|
SLEEP_FOREVER
|
||||||
|
};
|
||||||
|
|
||||||
|
class MyHwESP8266 : public MyHw
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
MyHwESP8266();
|
||||||
|
|
||||||
|
/* void init();
|
||||||
|
void watchdogReset();
|
||||||
|
void reboot();
|
||||||
|
unsigned long millis();
|
||||||
|
uint8_t readConfig(uint8_t pos);
|
||||||
|
void writeConfig(uint8_t pos, uint8_t value);
|
||||||
|
void readConfigBlock(void* buf, void * pos, size_t length);
|
||||||
|
void writeConfigBlock(void* pos, void* buf, size_t length); */
|
||||||
|
|
||||||
|
void sleep(unsigned long ms);
|
||||||
|
bool sleep(uint8_t interrupt, uint8_t mode, unsigned long ms);
|
||||||
|
uint8_t sleep(uint8_t interrupt1, uint8_t mode1, uint8_t interrupt2, uint8_t mode2, unsigned long ms);
|
||||||
|
#ifdef DEBUG
|
||||||
|
void debugPrint(bool isGW, const char *fmt, ... );
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // #ifdef ARDUINO_ARCH_ESP8266
|
||||||
@@ -163,7 +163,9 @@ typedef enum {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef BIT
|
||||||
#define BIT(n) ( 1<<(n) )
|
#define BIT(n) ( 1<<(n) )
|
||||||
|
#endif
|
||||||
// Create a bitmask of length len.
|
// Create a bitmask of length len.
|
||||||
#define BIT_MASK(len) ( BIT(len)-1 )
|
#define BIT_MASK(len) ( BIT(len)-1 )
|
||||||
// Create a bitfield mask of length starting at bit 'start'.
|
// Create a bitfield mask of length starting at bit 'start'.
|
||||||
|
|||||||
@@ -95,14 +95,12 @@ bool MySensor::isValidFirmware() {
|
|||||||
|
|
||||||
#ifdef WITH_LEDS_BLINKING
|
#ifdef WITH_LEDS_BLINKING
|
||||||
void MySensor::handleLedsBlinking() {
|
void MySensor::handleLedsBlinking() {
|
||||||
static unsigned long next_time = hw_millis() + ledBlinkPeriod;
|
|
||||||
|
|
||||||
// Just return if it is not the time...
|
// Just return if it is not the time...
|
||||||
// http://playground.arduino.cc/Code/TimingRollover
|
// http://playground.arduino.cc/Code/TimingRollover
|
||||||
if ((long)(hw_millis() - next_time) < 0)
|
if ((long)(hw_millis() - blink_next_time) < 0)
|
||||||
return;
|
return;
|
||||||
else
|
else
|
||||||
next_time = hw_millis() + ledBlinkPeriod;
|
blink_next_time = hw_millis() + ledBlinkPeriod;
|
||||||
|
|
||||||
// do the actual blinking
|
// do the actual blinking
|
||||||
if(countRx && countRx != 255) {
|
if(countRx && countRx != 255) {
|
||||||
|
|||||||
@@ -41,8 +41,13 @@
|
|||||||
|
|
||||||
// Set the hardware driver to use (initialized by MySensor-class)
|
// Set the hardware driver to use (initialized by MySensor-class)
|
||||||
//#if defined __AVR_ATmega328P__
|
//#if defined __AVR_ATmega328P__
|
||||||
|
#if defined(ARDUINO_ARCH_ESP8266)
|
||||||
|
#include "MyHwESP8266.h"
|
||||||
|
typedef MyHwESP8266 MyHwDriver;
|
||||||
|
#elif defined(ARDUINO_ARCH_AVR)
|
||||||
#include "MyHwATMega328.h"
|
#include "MyHwATMega328.h"
|
||||||
typedef MyHwATMega328 MyHwDriver;
|
typedef MyHwATMega328 MyHwDriver;
|
||||||
|
#endif
|
||||||
//#endif
|
//#endif
|
||||||
|
|
||||||
|
|
||||||
@@ -356,6 +361,7 @@ class MySensor
|
|||||||
|
|
||||||
unsigned long ledBlinkPeriod;
|
unsigned long ledBlinkPeriod;
|
||||||
void handleLedsBlinking(); // do the actual blinking
|
void handleLedsBlinking(); // do the actual blinking
|
||||||
|
unsigned long blink_next_time;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
MyTransport& radio;
|
MyTransport& radio;
|
||||||
|
|||||||
@@ -24,6 +24,7 @@
|
|||||||
* HMAC-SHA256 authentication with a readout-protected key.
|
* HMAC-SHA256 authentication with a readout-protected key.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
#if defined(ARDUINO_ARCH_AVR)
|
||||||
|
|
||||||
#include "MySigning.h"
|
#include "MySigning.h"
|
||||||
#include "MySigningAtsha204.h"
|
#include "MySigningAtsha204.h"
|
||||||
@@ -266,3 +267,4 @@ uint8_t* MySigningAtsha204::sha256(const uint8_t* data, size_t sz) {
|
|||||||
DEBUG_SIGNING_PRINTBUF(F("SHA:"), &rx_buffer[SHA204_BUFFER_POS_DATA], 32);
|
DEBUG_SIGNING_PRINTBUF(F("SHA:"), &rx_buffer[SHA204_BUFFER_POS_DATA], 32);
|
||||||
return &rx_buffer[SHA204_BUFFER_POS_DATA];
|
return &rx_buffer[SHA204_BUFFER_POS_DATA];
|
||||||
}
|
}
|
||||||
|
#endif // #if defined(ARDUINO_ARCH_AVR)
|
||||||
|
|||||||
@@ -0,0 +1,226 @@
|
|||||||
|
/**
|
||||||
|
* 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 - Henrik EKblad
|
||||||
|
* Contribution by a-lurker and Anticimex,
|
||||||
|
* Contribution by Norbert Truchsess <norbert.truchsess@t-online.de>
|
||||||
|
* Contribution by Ivo Pullens (ESP8266 support)
|
||||||
|
*
|
||||||
|
* DESCRIPTION
|
||||||
|
* The EthernetGateway sends data received from sensors to the WiFi link.
|
||||||
|
* The gateway also accepts input on ethernet interface, which is then sent out to the radio network.
|
||||||
|
*
|
||||||
|
* VERA CONFIGURATION:
|
||||||
|
* Enter "ip-number:port" in the ip-field of the Arduino GW device. This will temporarily override any serial configuration for the Vera plugin.
|
||||||
|
* E.g. If you want to use the defualt values in this sketch enter: 192.168.178.66:5003
|
||||||
|
*
|
||||||
|
* LED purposes:
|
||||||
|
* - To use the feature, uncomment WITH_LEDS_BLINKING in MyConfig.h
|
||||||
|
* - RX (green) - blink fast on radio message recieved. In inclusion mode will blink fast only on presentation recieved
|
||||||
|
* - TX (yellow) - blink fast on radio message transmitted. In inclusion mode will blink slowly
|
||||||
|
* - ERR (red) - fast blink on error during transmission error or recieve crc error
|
||||||
|
*
|
||||||
|
* See http://www.mysensors.org/build/ethernet_gateway for wiring instructions.
|
||||||
|
* The ESP8266 however requires different wiring:
|
||||||
|
* nRF24L01+ ESP8266
|
||||||
|
* VCC VCC
|
||||||
|
* CE GPIO4
|
||||||
|
* CSN/CS GPIO15
|
||||||
|
* SCK GPIO14
|
||||||
|
* MISO GPIO12
|
||||||
|
* MOSI GPIO13
|
||||||
|
*
|
||||||
|
* Not all ESP8266 modules have all pins available on their external interface.
|
||||||
|
* This code has been tested on an ESP-12 module.
|
||||||
|
* The ESP8266 requires a certain pin configuration to download code, and another one to run code:
|
||||||
|
* - Connect REST (reset) via 10K pullup resistor to VCC, and via switch to GND ('reset switch')
|
||||||
|
* - Connect GPIO15 via 10K pulldown resistor to GND
|
||||||
|
* - Connect CH_PD via 10K resistor to VCC
|
||||||
|
* - Connect GPIO2 via 10K resistor to VCC
|
||||||
|
* - Connect GPIO0 via 10K resistor to VCC, and via switch to GND ('bootload switch')
|
||||||
|
*
|
||||||
|
* Inclusion mode button:
|
||||||
|
* - Connect GPIO5 via switch to GND ('inclusion switch')
|
||||||
|
*
|
||||||
|
* Hardware SHA204 signing is currently not supported!
|
||||||
|
*
|
||||||
|
* Make sure to fill in your ssid and WiFi password below for ssid & pass.
|
||||||
|
*/
|
||||||
|
#define NO_PORTB_PINCHANGES
|
||||||
|
|
||||||
|
#include <SPI.h>
|
||||||
|
|
||||||
|
#include <MySigningNone.h>
|
||||||
|
#include <MySigningAtsha204Soft.h>
|
||||||
|
#include <MyTransportNRF24.h>
|
||||||
|
#include <MyTransportRFM69.h>
|
||||||
|
#include <EEPROM.h>
|
||||||
|
#include <MyHwESP8266.h>
|
||||||
|
#include <ESP8266WiFi.h>
|
||||||
|
|
||||||
|
#include <MyParserSerial.h>
|
||||||
|
#include <MySensor.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include "GatewayUtil.h"
|
||||||
|
|
||||||
|
const char *ssid = "MySSID"; // cannot be longer than 32 characters!
|
||||||
|
const char *pass = "MyVerySecretPassword"; //
|
||||||
|
|
||||||
|
#define INCLUSION_MODE_TIME 1 // Number of minutes inclusion mode is enabled
|
||||||
|
#define INCLUSION_MODE_PIN 5 // Digital pin used for inclusion mode button
|
||||||
|
|
||||||
|
#define RADIO_CE_PIN 4 // radio chip enable
|
||||||
|
#define RADIO_SPI_SS_PIN 15 // radio SPI serial select
|
||||||
|
|
||||||
|
#ifdef WITH_LEDS_BLINKING
|
||||||
|
#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
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
// 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)
|
||||||
|
#ifdef MY_SIGNING_FEATURE
|
||||||
|
MySigningNone signer;
|
||||||
|
//MySigningAtsha204Soft signer;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Hardware profile
|
||||||
|
MyHwESP8266 hw;
|
||||||
|
|
||||||
|
// Construct MySensors library (signer needed if MY_SIGNING_FEATURE is turned on in MyConfig.h)
|
||||||
|
// To use LEDs blinking, uncomment WITH_LEDS_BLINKING in MyConfig.h
|
||||||
|
MySensor gw(transport, hw
|
||||||
|
#ifdef MY_SIGNING_FEATURE
|
||||||
|
, signer
|
||||||
|
#endif
|
||||||
|
#ifdef WITH_LEDS_BLINKING
|
||||||
|
, RADIO_RX_LED_PIN, RADIO_TX_LED_PIN, RADIO_ERROR_LED_PIN
|
||||||
|
#endif
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
#define IP_PORT 5003 // The port you want to open
|
||||||
|
|
||||||
|
// a R/W server on the port
|
||||||
|
WiFiServer server(IP_PORT);
|
||||||
|
// handle to open connection
|
||||||
|
WiFiClient client;
|
||||||
|
|
||||||
|
char inputString[MAX_RECEIVE_LENGTH] = ""; // A string to hold incoming commands from serial/ethernet interface
|
||||||
|
int inputPos = 0;
|
||||||
|
bool sentReady = false;
|
||||||
|
|
||||||
|
void output(const char *fmt, ... ) {
|
||||||
|
va_list args;
|
||||||
|
va_start (args, fmt );
|
||||||
|
vsnprintf_P(serialBuffer, MAX_SEND_LENGTH, fmt, args);
|
||||||
|
va_end (args);
|
||||||
|
Serial.print(serialBuffer);
|
||||||
|
server.write(serialBuffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
void setup()
|
||||||
|
{
|
||||||
|
// Setup console
|
||||||
|
hw_init();
|
||||||
|
|
||||||
|
Serial.println(); Serial.println();
|
||||||
|
Serial.println("ESP8266 MySensors Gateway");
|
||||||
|
Serial.print("Connecting to "); Serial.println(ssid);
|
||||||
|
|
||||||
|
(void)WiFi.begin(ssid, pass);
|
||||||
|
while (WiFi.status() != WL_CONNECTED) {
|
||||||
|
delay(500);
|
||||||
|
Serial.print(".");
|
||||||
|
}
|
||||||
|
Serial.println("Connected!");
|
||||||
|
Serial.print("IP: "); Serial.println(WiFi.localIP());
|
||||||
|
Serial.flush();
|
||||||
|
|
||||||
|
setupGateway(INCLUSION_MODE_PIN, INCLUSION_MODE_TIME, output);
|
||||||
|
|
||||||
|
// 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();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
gw.process();
|
||||||
|
|
||||||
|
checkButtonTriggeredInclusion();
|
||||||
|
checkInclusionFinished();
|
||||||
|
|
||||||
|
//check if there are any new clients
|
||||||
|
if (server.hasClient())
|
||||||
|
{
|
||||||
|
if (client)
|
||||||
|
{
|
||||||
|
client.stop();
|
||||||
|
}
|
||||||
|
client = server.available();
|
||||||
|
output(PSTR("0;0;%d;0;%d;Gateway startup complete.\n"), C_INTERNAL, I_GATEWAY_READY);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (client) {
|
||||||
|
if (!client.connected()) {
|
||||||
|
client.stop();
|
||||||
|
} else if (client.available()) {
|
||||||
|
// read the bytes incoming from the client
|
||||||
|
char inChar = client.read();
|
||||||
|
if (inputPos<MAX_RECEIVE_LENGTH-1) {
|
||||||
|
// if newline then command is complete
|
||||||
|
if (inChar == '\n') {
|
||||||
|
Serial.println("Finished");
|
||||||
|
// a command was issued by the client
|
||||||
|
// we will now try to send it to the actuator
|
||||||
|
inputString[inputPos] = 0;
|
||||||
|
|
||||||
|
// echo the string to the serial port
|
||||||
|
Serial.print(inputString);
|
||||||
|
|
||||||
|
parseAndSend(gw, inputString);
|
||||||
|
|
||||||
|
// clear the string:
|
||||||
|
inputPos = 0;
|
||||||
|
} else {
|
||||||
|
// add it to the inputString:
|
||||||
|
inputString[inputPos] = inChar;
|
||||||
|
inputPos++;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Incoming message too long. Throw away
|
||||||
|
inputPos = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,131 @@
|
|||||||
|
#ifndef __GATEWAYUTIL_H__
|
||||||
|
#define __GATEWAYUTIL_H__
|
||||||
|
|
||||||
|
#ifdef ARDUINO
|
||||||
|
|
||||||
|
|
||||||
|
static uint8_t inclusionTime = 1; // Number of minutes inclusion mode is enabled
|
||||||
|
static uint8_t pinInclusion = 3; // Input pin that should trigger inclusion mode
|
||||||
|
|
||||||
|
#define MAX_RECEIVE_LENGTH 100 // Max buffersize needed for messages coming from controller
|
||||||
|
#define MAX_SEND_LENGTH 120 // Max buffersize needed for messages destined for controller
|
||||||
|
|
||||||
|
static volatile boolean buttonTriggeredInclusion;
|
||||||
|
static boolean inclusionMode; // Keeps track on inclusion mode
|
||||||
|
bool inclusionButtonSupported = false;
|
||||||
|
void (*serial)(const char *fmt, ... );
|
||||||
|
|
||||||
|
MyParserSerial parser;
|
||||||
|
|
||||||
|
void setInclusionMode(boolean newMode);
|
||||||
|
|
||||||
|
char convBuf[MAX_PAYLOAD*2+1];
|
||||||
|
char serialBuffer[MAX_SEND_LENGTH]; // Buffer for building string when sending data to vera
|
||||||
|
unsigned long inclusionStartTime;
|
||||||
|
|
||||||
|
|
||||||
|
void startInclusionInterrupt() {
|
||||||
|
buttonTriggeredInclusion = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setupGateway(uint8_t _inc, uint8_t _incTime, void (* _serial)(const char *, ... )) {
|
||||||
|
inclusionMode = 0;
|
||||||
|
buttonTriggeredInclusion = false;
|
||||||
|
serial = _serial;
|
||||||
|
|
||||||
|
inclusionTime = _incTime;
|
||||||
|
inclusionButtonSupported = (_inc != 255);
|
||||||
|
if (inclusionButtonSupported)
|
||||||
|
{
|
||||||
|
pinInclusion = _inc;
|
||||||
|
|
||||||
|
// Setup digital in that triggers inclusion mode
|
||||||
|
pinMode(pinInclusion, INPUT_PULLUP);
|
||||||
|
|
||||||
|
// Add interrupt for inclusion button to pin
|
||||||
|
attachInterrupt(pinInclusion, startInclusionInterrupt, FALLING);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void incomingMessage(const MyMessage &message) {
|
||||||
|
// if (mGetCommand(message) == C_PRESENTATION && inclusionMode) {
|
||||||
|
// gw.rxBlink(3);
|
||||||
|
// } else {
|
||||||
|
// gw.rxBlink(1);
|
||||||
|
// }
|
||||||
|
// Pass along the message from sensors to serial line
|
||||||
|
serial(PSTR("%d;%d;%d;%d;%d;%s\n"),message.sender, message.sensor, mGetCommand(message), mGetAck(message), message.type, message.getString(convBuf));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void checkButtonTriggeredInclusion() {
|
||||||
|
if (inclusionButtonSupported)
|
||||||
|
{
|
||||||
|
if (buttonTriggeredInclusion) {
|
||||||
|
// Ok, someone pressed the inclusion button on the gateway
|
||||||
|
// start inclusion mode for 1 munute.
|
||||||
|
#ifdef DEBUG
|
||||||
|
serial(PSTR("0;0;%d;0;%d;Inclusion started by button.\n"), C_INTERNAL, I_LOG_MESSAGE);
|
||||||
|
#endif
|
||||||
|
buttonTriggeredInclusion = false;
|
||||||
|
setInclusionMode(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void checkInclusionFinished() {
|
||||||
|
if (inclusionMode && millis()-inclusionStartTime>60000UL*inclusionTime) {
|
||||||
|
// inclusionTimeInMinutes minute(s) has passed.. stop inclusion mode
|
||||||
|
setInclusionMode(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void parseAndSend(MySensor &gw, char *commandBuffer) {
|
||||||
|
boolean ok;
|
||||||
|
MyMessage &msg = gw.getLastMessage();
|
||||||
|
|
||||||
|
if (parser.parse(msg, commandBuffer)) {
|
||||||
|
uint8_t command = mGetCommand(msg);
|
||||||
|
|
||||||
|
if (msg.destination==GATEWAY_ADDRESS && command==C_INTERNAL) {
|
||||||
|
// Handle messages directed to gateway
|
||||||
|
if (msg.type == I_VERSION) {
|
||||||
|
// Request for version
|
||||||
|
serial(PSTR("0;0;%d;0;%d;%s\n"), C_INTERNAL, I_VERSION, LIBRARY_VERSION);
|
||||||
|
} else if (msg.type == I_INCLUSION_MODE) {
|
||||||
|
// Request to change inclusion mode
|
||||||
|
setInclusionMode(atoi(msg.data) == 1);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
#ifdef WITH_LEDS_BLINKING
|
||||||
|
gw.txBlink(1);
|
||||||
|
#endif
|
||||||
|
ok = gw.sendRoute(msg);
|
||||||
|
if (!ok) {
|
||||||
|
#ifdef WITH_LEDS_BLINKING
|
||||||
|
gw.errBlink(1);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void setInclusionMode(boolean newMode) {
|
||||||
|
if (newMode != inclusionMode) {
|
||||||
|
inclusionMode = newMode;
|
||||||
|
// Send back mode change on serial line to ack command
|
||||||
|
serial(PSTR("0;0;%d;0;%d;%d\n"), C_INTERNAL, I_INCLUSION_MODE, inclusionMode?1:0);
|
||||||
|
|
||||||
|
if (inclusionMode) {
|
||||||
|
inclusionStartTime = millis();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#else
|
||||||
|
#error This example is only for use on Arduino.
|
||||||
|
#endif // ARDUINO
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
#if defined(ARDUINO_ARCH_AVR)
|
||||||
|
|
||||||
#include "Arduino.h"
|
#include "Arduino.h"
|
||||||
#include "ATSHA204.h"
|
#include "ATSHA204.h"
|
||||||
|
|
||||||
@@ -572,3 +574,5 @@ uint8_t ATSHA204Class::sha204c_check_crc(uint8_t *response)
|
|||||||
return (crc[0] == response[count] && crc[1] == response[count + 1])
|
return (crc[0] == response[count] && crc[1] == response[count + 1])
|
||||||
? SHA204_SUCCESS : SHA204_BAD_CRC;
|
? SHA204_SUCCESS : SHA204_BAD_CRC;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif // defined(ARDUINO_ARCH_AVR)
|
||||||
@@ -498,7 +498,7 @@ void RF24::begin(void)
|
|||||||
|
|
||||||
// Reset current status
|
// Reset current status
|
||||||
// Notice reset and flush is the last thing we do
|
// Notice reset and flush is the last thing we do
|
||||||
write_register(STATUS,_BV(RX_DR) | _BV(TX_DS) | _BV(MAX_RT) );
|
write_register(RF24_STATUS,_BV(RX_DR) | _BV(TX_DS) | _BV(MAX_RT) );
|
||||||
|
|
||||||
// Set up default configuration. Callers can always change it later.
|
// Set up default configuration. Callers can always change it later.
|
||||||
// This channel should be universally safe and not bleed over into adjacent
|
// This channel should be universally safe and not bleed over into adjacent
|
||||||
@@ -525,7 +525,7 @@ void RF24::startListening(void)
|
|||||||
powerUp();
|
powerUp();
|
||||||
#endif
|
#endif
|
||||||
write_register(CONFIG, read_register(CONFIG) | _BV(PRIM_RX));
|
write_register(CONFIG, read_register(CONFIG) | _BV(PRIM_RX));
|
||||||
write_register(STATUS, _BV(RX_DR) | _BV(TX_DS) | _BV(MAX_RT) );
|
write_register(RF24_STATUS, _BV(RX_DR) | _BV(TX_DS) | _BV(MAX_RT) );
|
||||||
|
|
||||||
// Restore the pipe0 adddress, if exists
|
// Restore the pipe0 adddress, if exists
|
||||||
if (pipe0_reading_address[0] > 0){
|
if (pipe0_reading_address[0] > 0){
|
||||||
@@ -546,22 +546,31 @@ void RF24::startListening(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************/
|
/****************************************************************************/
|
||||||
static const uint8_t child_pipe_enable[] PROGMEM =
|
static uint8_t get_child_pipe_mask(const uint8_t idx)
|
||||||
{
|
{
|
||||||
ERX_P0, ERX_P1, ERX_P2, ERX_P3, ERX_P4, ERX_P5
|
static const uint8_t child_pipe_enable[] PROGMEM =
|
||||||
};
|
{
|
||||||
|
_BV(ERX_P0), _BV(ERX_P1), _BV(ERX_P2), _BV(ERX_P3), _BV(ERX_P4), _BV(ERX_P5)
|
||||||
|
};
|
||||||
|
#ifdef ESP8266
|
||||||
|
return child_pipe_enable[idx];
|
||||||
|
#else
|
||||||
|
return pgm_read_byte(&child_pipe_enable[idx]);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
void RF24::stopListening(void)
|
void RF24::stopListening(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
ce(LOW);
|
ce(LOW);
|
||||||
#if defined(__arm__)
|
#if defined(__arm__)
|
||||||
delayMicroseconds(300);
|
delayMicroseconds(300);
|
||||||
#endif
|
#endif
|
||||||
delayMicroseconds(130);
|
delayMicroseconds(130);
|
||||||
|
|
||||||
if(read_register(FEATURE) & _BV(EN_ACK_PAY)){
|
if(read_register(FEATURE) & _BV(EN_ACK_PAY)){
|
||||||
flush_tx();
|
flush_tx();
|
||||||
}
|
}
|
||||||
|
|
||||||
//flush_rx();
|
//flush_rx();
|
||||||
write_register(CONFIG, ( read_register(CONFIG) ) & ~_BV(PRIM_RX) );
|
write_register(CONFIG, ( read_register(CONFIG) ) & ~_BV(PRIM_RX) );
|
||||||
|
|
||||||
@@ -569,13 +578,13 @@ void RF24::stopListening(void)
|
|||||||
// for 3 pins solution TX mode is only left with additonal powerDown/powerUp cycle
|
// for 3 pins solution TX mode is only left with additonal powerDown/powerUp cycle
|
||||||
if (ce_pin == csn_pin) {
|
if (ce_pin == csn_pin) {
|
||||||
powerDown();
|
powerDown();
|
||||||
powerUp();
|
powerUp();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
write_register(EN_RXADDR,read_register(EN_RXADDR) | _BV(pgm_read_byte(&child_pipe_enable[0]))); // Enable RX on pipe0
|
|
||||||
|
write_register(EN_RXADDR,read_register(EN_RXADDR) | get_child_pipe_mask(0)); // Enable RX on pipe0
|
||||||
|
|
||||||
delayMicroseconds(100);
|
delayMicroseconds(100);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************/
|
/****************************************************************************/
|
||||||
@@ -636,7 +645,7 @@ bool RF24::write( const void* buf, uint8_t len, const bool multicast )
|
|||||||
|
|
||||||
ce(LOW);
|
ce(LOW);
|
||||||
|
|
||||||
uint8_t status = write_register(STATUS,_BV(RX_DR) | _BV(TX_DS) | _BV(MAX_RT) );
|
uint8_t status = write_register(RF24_STATUS,_BV(RX_DR) | _BV(TX_DS) | _BV(MAX_RT) );
|
||||||
|
|
||||||
//Max retries exceeded
|
//Max retries exceeded
|
||||||
if( status & _BV(MAX_RT)){
|
if( status & _BV(MAX_RT)){
|
||||||
@@ -686,7 +695,7 @@ bool RF24::writeBlocking( const void* buf, uint8_t len, uint32_t timeout )
|
|||||||
/****************************************************************************/
|
/****************************************************************************/
|
||||||
|
|
||||||
void RF24::reUseTX(){
|
void RF24::reUseTX(){
|
||||||
write_register(STATUS,_BV(MAX_RT) ); //Clear max retry flag
|
write_register(RF24_STATUS,_BV(MAX_RT) ); //Clear max retry flag
|
||||||
spiTrans( REUSE_TX_PL );
|
spiTrans( REUSE_TX_PL );
|
||||||
ce(LOW); //Re-Transfer packet
|
ce(LOW); //Re-Transfer packet
|
||||||
ce(HIGH);
|
ce(HIGH);
|
||||||
@@ -709,7 +718,7 @@ bool RF24::writeFast( const void* buf, uint8_t len, const bool multicast )
|
|||||||
|
|
||||||
if( get_status() & _BV(MAX_RT)){
|
if( get_status() & _BV(MAX_RT)){
|
||||||
//reUseTX(); //Set re-transmit
|
//reUseTX(); //Set re-transmit
|
||||||
write_register(STATUS,_BV(MAX_RT) ); //Clear max retry flag
|
write_register(RF24_STATUS,_BV(MAX_RT) ); //Clear max retry flag
|
||||||
return 0; //Return 0. The previous payload has been retransmitted
|
return 0; //Return 0. The previous payload has been retransmitted
|
||||||
//From the user perspective, if you get a 0, just keep trying to send the same payload
|
//From the user perspective, if you get a 0, just keep trying to send the same payload
|
||||||
}
|
}
|
||||||
@@ -777,7 +786,7 @@ bool RF24::txStandBy(){
|
|||||||
#endif
|
#endif
|
||||||
while( ! (read_register(FIFO_STATUS) & _BV(TX_EMPTY)) ){
|
while( ! (read_register(FIFO_STATUS) & _BV(TX_EMPTY)) ){
|
||||||
if( get_status() & _BV(MAX_RT)){
|
if( get_status() & _BV(MAX_RT)){
|
||||||
write_register(STATUS,_BV(MAX_RT) );
|
write_register(RF24_STATUS,_BV(MAX_RT) );
|
||||||
ce(LOW);
|
ce(LOW);
|
||||||
flush_tx(); //Non blocking, flush the data
|
flush_tx(); //Non blocking, flush the data
|
||||||
return 0;
|
return 0;
|
||||||
@@ -802,7 +811,7 @@ bool RF24::txStandBy(uint32_t timeout){
|
|||||||
|
|
||||||
while( ! (read_register(FIFO_STATUS) & _BV(TX_EMPTY)) ){
|
while( ! (read_register(FIFO_STATUS) & _BV(TX_EMPTY)) ){
|
||||||
if( get_status() & _BV(MAX_RT)){
|
if( get_status() & _BV(MAX_RT)){
|
||||||
write_register(STATUS,_BV(MAX_RT) );
|
write_register(RF24_STATUS,_BV(MAX_RT) );
|
||||||
ce(LOW); //Set re-transmit
|
ce(LOW); //Set re-transmit
|
||||||
ce(HIGH);
|
ce(HIGH);
|
||||||
if(millis() - start >= timeout){
|
if(millis() - start >= timeout){
|
||||||
@@ -891,7 +900,7 @@ void RF24::read( void* buf, uint8_t len ){
|
|||||||
read_payload( buf, len );
|
read_payload( buf, len );
|
||||||
|
|
||||||
//Clear the two possible interrupt flags with one command
|
//Clear the two possible interrupt flags with one command
|
||||||
write_register(STATUS,_BV(RX_DR) | _BV(MAX_RT) | _BV(TX_DS) );
|
write_register(RF24_STATUS,_BV(RX_DR) | _BV(MAX_RT) | _BV(TX_DS) );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -901,7 +910,7 @@ void RF24::whatHappened(bool& tx_ok,bool& tx_fail,bool& rx_ready)
|
|||||||
{
|
{
|
||||||
// Read the status & reset the status in one easy call
|
// Read the status & reset the status in one easy call
|
||||||
// Or is that such a good idea?
|
// Or is that such a good idea?
|
||||||
uint8_t status = write_register(STATUS,_BV(RX_DR) | _BV(TX_DS) | _BV(MAX_RT) );
|
uint8_t status = write_register(RF24_STATUS,_BV(RX_DR) | _BV(TX_DS) | _BV(MAX_RT) );
|
||||||
|
|
||||||
// Report to the user what happened
|
// Report to the user what happened
|
||||||
tx_ok = status & _BV(TX_DS);
|
tx_ok = status & _BV(TX_DS);
|
||||||
@@ -972,7 +981,7 @@ void RF24::openReadingPipe(uint8_t child, uint64_t address)
|
|||||||
// Note it would be more efficient to set all of the bits for all open
|
// Note it would be more efficient to set all of the bits for all open
|
||||||
// pipes at once. However, I thought it would make the calling code
|
// pipes at once. However, I thought it would make the calling code
|
||||||
// more simple to do it this way.
|
// more simple to do it this way.
|
||||||
write_register(EN_RXADDR,read_register(EN_RXADDR) | _BV(pgm_read_byte(&child_pipe_enable[child])));
|
write_register(EN_RXADDR,read_register(EN_RXADDR) | get_child_pipe_mask(child));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1009,7 +1018,7 @@ void RF24::openReadingPipe(uint8_t child, const uint8_t *address)
|
|||||||
// Note it would be more efficient to set all of the bits for all open
|
// Note it would be more efficient to set all of the bits for all open
|
||||||
// pipes at once. However, I thought it would make the calling code
|
// pipes at once. However, I thought it would make the calling code
|
||||||
// more simple to do it this way.
|
// more simple to do it this way.
|
||||||
write_register(EN_RXADDR,read_register(EN_RXADDR) | _BV(pgm_read_byte(&child_pipe_enable[child])));
|
write_register(EN_RXADDR,read_register(EN_RXADDR) | get_child_pipe_mask(child));
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1018,7 +1027,7 @@ void RF24::openReadingPipe(uint8_t child, const uint8_t *address)
|
|||||||
|
|
||||||
void RF24::closeReadingPipe( uint8_t pipe )
|
void RF24::closeReadingPipe( uint8_t pipe )
|
||||||
{
|
{
|
||||||
write_register(EN_RXADDR,read_register(EN_RXADDR) & ~_BV(pgm_read_byte(&child_pipe_enable[pipe])));
|
write_register(EN_RXADDR,read_register(EN_RXADDR) & ~get_child_pipe_mask(pipe));
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************/
|
/****************************************************************************/
|
||||||
|
|||||||
@@ -87,7 +87,7 @@
|
|||||||
// Avoid spurious warnings
|
// Avoid spurious warnings
|
||||||
// Arduino DUE is arm and uses traditional PROGMEM constructs
|
// Arduino DUE is arm and uses traditional PROGMEM constructs
|
||||||
#if 1
|
#if 1
|
||||||
#if ! defined( NATIVE ) && defined( ARDUINO ) && ! defined(__arm__) && ! defined( CORE_TEENSY3 )
|
#if ! defined( NATIVE ) && defined( ARDUINO ) && ! defined(__arm__) && ! defined( CORE_TEENSY3 ) && ! defined(ESP8266)
|
||||||
#undef PROGMEM
|
#undef PROGMEM
|
||||||
#define PROGMEM __attribute__(( section(".progmem.data") ))
|
#define PROGMEM __attribute__(( section(".progmem.data") ))
|
||||||
#undef PSTR
|
#undef PSTR
|
||||||
@@ -97,18 +97,21 @@
|
|||||||
|
|
||||||
// Progmem is Arduino-specific
|
// Progmem is Arduino-specific
|
||||||
// Arduino DUE is arm and does not include avr/pgmspace
|
// Arduino DUE is arm and does not include avr/pgmspace
|
||||||
#if defined(ARDUINO) && ! defined(__arm__)
|
#if defined(__AVR__)
|
||||||
#include <avr/pgmspace.h>
|
#include <avr/pgmspace.h>
|
||||||
#define PRIPSTR "%S"
|
#define PRIPSTR "%S"
|
||||||
#else
|
#else
|
||||||
|
#if defined(ESP8266)
|
||||||
|
#include <pgmspace.h>
|
||||||
|
#else
|
||||||
#if ! defined(ARDUINO) // This doesn't work on Arduino DUE
|
#if ! defined(ARDUINO) // This doesn't work on Arduino DUE
|
||||||
typedef char const char;
|
typedef char const char;
|
||||||
#else // Fill in pgm_read_byte that is used, but missing from DUE
|
#else // Fill in pgm_read_byte that is used, but missing from DUE
|
||||||
#define pgm_read_byte(addr) (*(const unsigned char *)(addr))
|
#define pgm_read_byte(addr) (*(const unsigned char *)(addr))
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if !defined ( CORE_TEENSY ) && ! defined(ESP8266)
|
||||||
#if !defined ( CORE_TEENSY )
|
|
||||||
typedef uint16_t prog_uint16_t;
|
typedef uint16_t prog_uint16_t;
|
||||||
#define PSTR(x) (x)
|
#define PSTR(x) (x)
|
||||||
#define printf_P printf
|
#define printf_P printf
|
||||||
|
|||||||
@@ -384,8 +384,10 @@ void RFM69::writeReg(byte addr, byte value)
|
|||||||
void RFM69::select() {
|
void RFM69::select() {
|
||||||
noInterrupts();
|
noInterrupts();
|
||||||
//save current SPI settings
|
//save current SPI settings
|
||||||
|
#ifndef ESP8266
|
||||||
_SPCR = SPCR;
|
_SPCR = SPCR;
|
||||||
_SPSR = SPSR;
|
_SPSR = SPSR;
|
||||||
|
#endif
|
||||||
//set RFM69 SPI settings
|
//set RFM69 SPI settings
|
||||||
SPI.setDataMode(SPI_MODE0);
|
SPI.setDataMode(SPI_MODE0);
|
||||||
SPI.setBitOrder(MSBFIRST);
|
SPI.setBitOrder(MSBFIRST);
|
||||||
@@ -397,8 +399,10 @@ void RFM69::select() {
|
|||||||
void RFM69::unselect() {
|
void RFM69::unselect() {
|
||||||
digitalWrite(_slaveSelectPin, HIGH);
|
digitalWrite(_slaveSelectPin, HIGH);
|
||||||
//restore SPI settings to what they were before talking to RFM69
|
//restore SPI settings to what they were before talking to RFM69
|
||||||
|
#ifndef ESP8266
|
||||||
SPCR = _SPCR;
|
SPCR = _SPCR;
|
||||||
SPSR = _SPSR;
|
SPSR = _SPSR;
|
||||||
|
#endif
|
||||||
interrupts();
|
interrupts();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -43,6 +43,10 @@
|
|||||||
#elif defined(__AVR_ATmega644P__) || defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega2560__)
|
#elif defined(__AVR_ATmega644P__) || defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega2560__)
|
||||||
#define RF69_IRQ_PIN 2
|
#define RF69_IRQ_PIN 2
|
||||||
#define RF69_IRQ_NUM 2
|
#define RF69_IRQ_NUM 2
|
||||||
|
#elif defined(ARDUINO_ARCH_ESP8266)
|
||||||
|
// TODO !! Untested code! Entering unknown territory...
|
||||||
|
#define RF69_IRQ_PIN 2
|
||||||
|
#define RF69_IRQ_NUM 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define CSMA_LIMIT -90 // upper RX signal sensitivity threshold in dBm for carrier sense access
|
#define CSMA_LIMIT -90 // upper RX signal sensitivity threshold in dBm for carrier sense access
|
||||||
|
|||||||
@@ -56,8 +56,10 @@ void SPIFlash::select() {
|
|||||||
#ifndef SPI_HAS_TRANSACTION
|
#ifndef SPI_HAS_TRANSACTION
|
||||||
noInterrupts();
|
noInterrupts();
|
||||||
#endif
|
#endif
|
||||||
|
#ifndef ESP8266
|
||||||
_SPCR = SPCR;
|
_SPCR = SPCR;
|
||||||
_SPSR = SPSR;
|
_SPSR = SPSR;
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef SPI_HAS_TRANSACTION
|
#ifdef SPI_HAS_TRANSACTION
|
||||||
SPI.beginTransaction(_settings);
|
SPI.beginTransaction(_settings);
|
||||||
@@ -80,15 +82,19 @@ void SPIFlash::unselect() {
|
|||||||
#else
|
#else
|
||||||
interrupts();
|
interrupts();
|
||||||
#endif
|
#endif
|
||||||
|
#ifndef ESP8266
|
||||||
SPCR = _SPCR;
|
SPCR = _SPCR;
|
||||||
SPSR = _SPSR;
|
SPSR = _SPSR;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/// setup SPI, read device ID etc...
|
/// setup SPI, read device ID etc...
|
||||||
boolean SPIFlash::initialize()
|
boolean SPIFlash::initialize()
|
||||||
{
|
{
|
||||||
|
#ifndef ESP8266
|
||||||
_SPCR = SPCR;
|
_SPCR = SPCR;
|
||||||
_SPSR = SPSR;
|
_SPSR = SPSR;
|
||||||
|
#endif
|
||||||
pinMode(_slaveSelectPin, OUTPUT);
|
pinMode(_slaveSelectPin, OUTPUT);
|
||||||
#ifdef SPI_HAS_TRANSACTION
|
#ifdef SPI_HAS_TRANSACTION
|
||||||
_settings = SPISettings(4000000, MSBFIRST, SPI_MODE0);
|
_settings = SPISettings(4000000, MSBFIRST, SPI_MODE0);
|
||||||
|
|||||||
@@ -31,7 +31,7 @@
|
|||||||
#define SETUP_RETR 0x04
|
#define SETUP_RETR 0x04
|
||||||
#define RF_CH 0x05
|
#define RF_CH 0x05
|
||||||
#define RF_SETUP 0x06
|
#define RF_SETUP 0x06
|
||||||
#define STATUS 0x07
|
#define RF24_STATUS 0x07
|
||||||
#define OBSERVE_TX 0x08
|
#define OBSERVE_TX 0x08
|
||||||
#define CD 0x09
|
#define CD 0x09
|
||||||
#define RX_ADDR_P0 0x0A
|
#define RX_ADDR_P0 0x0A
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <avr/io.h>
|
#if defined(__AVR__)
|
||||||
#include <avr/pgmspace.h>
|
#include <avr/pgmspace.h>
|
||||||
|
#define PRIPSTR "%S"
|
||||||
|
#elif defined(ESP8266)
|
||||||
|
#include <pgmspace.h>
|
||||||
|
#endif
|
||||||
#include "sha256.h"
|
#include "sha256.h"
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user