add: receive/receiveTime as optional sketch functions for handling
incoming messages
This commit is contained in:
@@ -39,7 +39,9 @@
|
||||
// HARDWARE
|
||||
#if defined(ARDUINO_ARCH_ESP8266)
|
||||
#include "drivers/ESP8266/SPI/SPI.cpp"
|
||||
#include "drivers/ESP8266/EEPROM/EEPROM.cpp"
|
||||
#include "core/MyHwESP8266.cpp"
|
||||
|
||||
// For ESP8266, we always enable gateway feature
|
||||
#define MY_GATEWAY_ESP8266
|
||||
#elif defined(ARDUINO_ARCH_AVR)
|
||||
@@ -110,7 +112,11 @@
|
||||
#endif
|
||||
#if defined(MY_GATEWAY_ESP8266)
|
||||
// GATEWAY - ESP8266
|
||||
// #include "drivers/ESP8266/ESP8266WiFi/src/ESP8266Wifi.cpp"
|
||||
|
||||
// #include "drivers/ESP8266/ESP8266WiFi/src/WifiClient.cpp"
|
||||
// #include "drivers/ESP8266/ESP8266WiFi/src/WifiServer.cpp"
|
||||
// #include "drivers/ESP8266/ESP8266WiFi/src/WifiUdp.cpp"
|
||||
#elif defined(MY_GATEWAY_W5100)
|
||||
// GATEWAY - W5100
|
||||
#include "drivers/AVR/Ethernet_W5100/utility/socket.cpp"
|
||||
@@ -212,18 +218,31 @@
|
||||
#include "core/MySensorCore.cpp"
|
||||
|
||||
extern void setup();
|
||||
extern void loop();
|
||||
//extern void loop();
|
||||
|
||||
// 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));
|
||||
|
||||
|
||||
#include <Arduino.h>
|
||||
// Initialize library and handle sketch functions like we want to
|
||||
int main() {
|
||||
int main(void) {
|
||||
init(); // Init Arduino
|
||||
#if defined(USBCON)
|
||||
USBDevice.attach();
|
||||
#endif
|
||||
_begin(); // Startup MySensors library
|
||||
setup(); // Call sketch setup
|
||||
while(1) {
|
||||
if (setup) setup(); // Call sketch setup
|
||||
for(;;) {
|
||||
_process(); // Process incoming data
|
||||
loop(); // Call sketch loop
|
||||
if (loop) loop(); // Call sketch loop
|
||||
#if !defined(ARDUINO_ARCH_ESP8266)
|
||||
if (serialEventRun) serialEventRun();
|
||||
#endif
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -47,8 +47,8 @@ inline void gatewayTransportProcess() {
|
||||
}
|
||||
} else {
|
||||
// Call incoming message callback if available
|
||||
if (_msgCallback != NULL) {
|
||||
_msgCallback(_msg);
|
||||
if (receive) {
|
||||
receive(_msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
*/
|
||||
|
||||
#include "MyHwESP8266.h"
|
||||
#include "drivers/ESP8266/EEPROM/EEPROM.cpp"
|
||||
|
||||
|
||||
/*
|
||||
int8_t pinIntTrigger = 0;
|
||||
|
||||
@@ -29,6 +29,11 @@
|
||||
//#include <SPI.h>
|
||||
#endif
|
||||
|
||||
|
||||
#define min(a,b) ((a)<(b)?(a):(b))
|
||||
#define max(a,b) ((a)>(b)?(a):(b))
|
||||
|
||||
|
||||
// Define these as macros to save valuable space
|
||||
|
||||
#define hwDigitalWrite(__pin, __value) (digitalWrite(__pin, __value))
|
||||
|
||||
@@ -30,7 +30,6 @@ MyMessage _msgTmp; // Buffer for temporary messages (acks and nonces among other
|
||||
|
||||
uint16_t _heartbeat;
|
||||
void (*_timeCallback)(unsigned long); // Callback for requested time messages
|
||||
void (*_msgCallback)(const MyMessage &); // Callback for incoming messages from other nodes and gateway.
|
||||
|
||||
|
||||
void _process() {
|
||||
@@ -60,10 +59,6 @@ static inline bool isValidParent( const uint8_t parent ) {
|
||||
}
|
||||
#endif
|
||||
|
||||
void setIncomingCallback(void (*msgCallback)(const MyMessage &)) {
|
||||
_msgCallback = msgCallback;
|
||||
}
|
||||
|
||||
void _begin() {
|
||||
#if !defined(MY_DISABLED_SERIAL)
|
||||
hwInit();
|
||||
@@ -218,8 +213,7 @@ void request(uint8_t childSensorId, uint8_t variableType, uint8_t destination) {
|
||||
_sendRoute(build(_msg, _nc.nodeId, destination, childSensorId, C_REQ, variableType, false).set(""));
|
||||
}
|
||||
|
||||
void requestTime(void (* timeCallback)(unsigned long)) {
|
||||
_timeCallback = timeCallback;
|
||||
void requestTime() {
|
||||
_sendRoute(build(_msg, _nc.nodeId, GATEWAY_ADDRESS, NODE_SENSOR_ID, C_INTERNAL, I_TIME, false).set(""));
|
||||
}
|
||||
|
||||
@@ -237,9 +231,9 @@ void _processInternalMessages() {
|
||||
isMetric = _msg.getString()[0] == 'M' ;
|
||||
_cc.isMetric = isMetric;
|
||||
hwWriteConfig(EEPROM_CONTROLLER_CONFIG_ADDRESS, isMetric);
|
||||
} else if (type == I_TIME && _timeCallback != NULL) {
|
||||
} else if (type == I_TIME && receiveTime) {
|
||||
// Deliver time to callback
|
||||
_timeCallback(_msg.getULong());
|
||||
receiveTime(_msg.getULong());
|
||||
}
|
||||
#if defined(MY_REPEATER_FEATURE)
|
||||
if (type == I_CHILDREN && _msg.getString()[0] == 'C') {
|
||||
|
||||
@@ -76,12 +76,6 @@ struct ControllerConfig {
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Set the callback method for incoming messages
|
||||
*
|
||||
* @param incomingMessageCallback Callback function for incoming messages from other nodes or controller and request responses.
|
||||
*/
|
||||
void setIncomingCallback(void (* msgCallback)(const MyMessage &)=NULL);
|
||||
|
||||
/**
|
||||
* Return this nodes id.
|
||||
@@ -144,11 +138,10 @@ void sendHeartbeat(void);
|
||||
void request(uint8_t childSensorId, uint8_t variableType, uint8_t destination=GATEWAY_ADDRESS);
|
||||
|
||||
/**
|
||||
* Requests time from controller. Answer will be delivered to callback.
|
||||
* Requests time from controller. Answer will be delivered to receiveTime function in sketch.
|
||||
*
|
||||
* @param callback for time request. Incoming argument is seconds since 1970.
|
||||
*/
|
||||
void requestTime(void (* timeCallback)(unsigned long));
|
||||
void requestTime();
|
||||
|
||||
|
||||
|
||||
@@ -232,10 +225,12 @@ boolean _sendRoute(MyMessage &message);
|
||||
extern NodeConfig _nc;
|
||||
extern MyMessage _msg; // Buffer for incoming messages.
|
||||
extern MyMessage _msgTmp; // Buffer for temporary messages (acks and nonces among others).
|
||||
extern void (*_msgCallback)(const MyMessage &); // Callback for incoming messages from other nodes and gateway.
|
||||
#ifdef MY_DEBUG
|
||||
extern char _convBuf[MAX_PAYLOAD*2+1];
|
||||
#endif
|
||||
void receive(const MyMessage &message) __attribute__((weak));
|
||||
void receiveTime(unsigned long) __attribute__((weak));
|
||||
void presentation() __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) {
|
||||
|
||||
@@ -282,8 +282,8 @@ inline void transportProcess() {
|
||||
}
|
||||
#endif
|
||||
// Call incoming message callback if available
|
||||
if (_msgCallback != NULL) {
|
||||
_msgCallback(_msg);
|
||||
if (receive) {
|
||||
receive(_msg);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
#define WIFIUDP_H
|
||||
|
||||
#include <Udp.h>
|
||||
#include <include/slist.h>
|
||||
#include "include/slist.h"
|
||||
|
||||
#define UDP_TX_PACKET_MAX_SIZE 8192
|
||||
|
||||
|
||||
@@ -32,16 +32,16 @@
|
||||
#ifndef __LWIP_API_H__
|
||||
#define __LWIP_API_H__
|
||||
|
||||
#include "lwip/opt.h"
|
||||
#include "opt.h"
|
||||
|
||||
#if LWIP_NETCONN /* don't build if not configured for use in lwipopts.h */
|
||||
|
||||
#include <stddef.h> /* for size_t */
|
||||
|
||||
#include "lwip/netbuf.h"
|
||||
#include "lwip/sys.h"
|
||||
#include "lwip/ip_addr.h"
|
||||
#include "lwip/err.h"
|
||||
#include "netbuf.h"
|
||||
#include "sys.h"
|
||||
#include "ip_addr.h"
|
||||
#include "err.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
||||
@@ -32,17 +32,17 @@
|
||||
#ifndef __LWIP_API_MSG_H__
|
||||
#define __LWIP_API_MSG_H__
|
||||
|
||||
#include "lwip/opt.h"
|
||||
#include "opt.h"
|
||||
|
||||
#if LWIP_NETCONN /* don't build if not configured for use in lwipopts.h */
|
||||
|
||||
#include <stddef.h> /* for size_t */
|
||||
|
||||
#include "lwip/ip_addr.h"
|
||||
#include "lwip/err.h"
|
||||
#include "lwip/sys.h"
|
||||
#include "lwip/igmp.h"
|
||||
#include "lwip/api.h"
|
||||
#include "ip_addr.h"
|
||||
#include "err.h"
|
||||
#include "sys.h"
|
||||
#include "igmp.h"
|
||||
#include "api.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
||||
@@ -40,7 +40,7 @@
|
||||
#define BIG_ENDIAN 4321
|
||||
#endif
|
||||
|
||||
#include "arch/cc.h"
|
||||
#include "../arch/cc.h"
|
||||
|
||||
/** Temporary: define format string for size_t if not defined in cc.h */
|
||||
#ifndef SZT_F
|
||||
|
||||
@@ -44,12 +44,12 @@
|
||||
#ifndef __LWIP_AUTOIP_H__
|
||||
#define __LWIP_AUTOIP_H__
|
||||
|
||||
#include "lwip/opt.h"
|
||||
#include "opt.h"
|
||||
|
||||
#if LWIP_AUTOIP /* don't build if not configured for use in lwipopts.h */
|
||||
|
||||
#include "lwip/netif.h"
|
||||
#include "lwip/udp.h"
|
||||
#include "netif.h"
|
||||
#include "udp.h"
|
||||
#include "netif/etharp.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
#ifndef __LWIP_DEBUG_H__
|
||||
#define __LWIP_DEBUG_H__
|
||||
|
||||
#include "lwip/arch.h"
|
||||
#include "arch.h"
|
||||
|
||||
/** lower two bits indicate debug level
|
||||
* - 0 all
|
||||
|
||||
@@ -33,8 +33,8 @@
|
||||
#define __LWIP_DEF_H__
|
||||
|
||||
/* arch.h might define NULL already */
|
||||
#include "lwip/arch.h"
|
||||
#include "lwip/opt.h"
|
||||
#include "arch.h"
|
||||
#include "opt.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
||||
@@ -4,12 +4,12 @@
|
||||
#ifndef __LWIP_DHCP_H__
|
||||
#define __LWIP_DHCP_H__
|
||||
|
||||
#include "lwip/opt.h"
|
||||
#include "opt.h"
|
||||
|
||||
#if LWIP_DHCP /* don't build if not configured for use in lwipopts.h */
|
||||
|
||||
#include "lwip/netif.h"
|
||||
#include "lwip/udp.h"
|
||||
#include "netif.h"
|
||||
#include "udp.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
#ifndef __LWIP_DNS_H__
|
||||
#define __LWIP_DNS_H__
|
||||
|
||||
#include "lwip/opt.h"
|
||||
#include "opt.h"
|
||||
|
||||
#if LWIP_DNS /* don't build if not configured for use in lwipopts.h */
|
||||
|
||||
|
||||
@@ -32,8 +32,8 @@
|
||||
#ifndef __LWIP_ERR_H__
|
||||
#define __LWIP_ERR_H__
|
||||
|
||||
#include "lwip/opt.h"
|
||||
#include "lwip/arch.h"
|
||||
#include "opt.h"
|
||||
#include "arch.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
||||
@@ -32,10 +32,10 @@
|
||||
#ifndef __LWIP_ICMP_H__
|
||||
#define __LWIP_ICMP_H__
|
||||
|
||||
#include "lwip/opt.h"
|
||||
#include "lwip/pbuf.h"
|
||||
#include "lwip/ip_addr.h"
|
||||
#include "lwip/netif.h"
|
||||
#include "opt.h"
|
||||
#include "pbuf.h"
|
||||
#include "ip_addr.h"
|
||||
#include "netif.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@@ -74,9 +74,9 @@ enum icmp_te_type {
|
||||
* is splitted to two u16_t like ICMP echo needs it.
|
||||
* This header is also used for other ICMP types that do not
|
||||
* use the data part.
|
||||
* 定义ICMP回送请求报文首部结构,
|
||||
* 由于所有ICMP报文首部有很大相似性,
|
||||
* 该结构同样适用于其它ICMP报文。
|
||||
* ����ICMP�����������ײ��ṹ��
|
||||
* ��������ICMP�����ײ��кܴ������ԣ�
|
||||
* �ýṹͬ������������ICMP���ġ�
|
||||
*/
|
||||
PACK_STRUCT_BEGIN
|
||||
struct icmp_echo_hdr {
|
||||
@@ -91,11 +91,11 @@ PACK_STRUCT_END
|
||||
# include "arch/epstruct.h"
|
||||
#endif
|
||||
|
||||
//读取ICMP首部中字段
|
||||
//��ȡICMP�ײ����ֶ�
|
||||
#define ICMPH_TYPE(hdr) ((hdr)->type)
|
||||
#define ICMPH_CODE(hdr) ((hdr)->code)
|
||||
|
||||
/** Combines type and code to an u16_t 向ICMP报文首部字段中写入相应值*/
|
||||
/** Combines type and code to an u16_t ��ICMP�����ײ��ֶ���д����Ӧֵ*/
|
||||
#define ICMPH_TYPE_SET(hdr, t) ((hdr)->type = (t))
|
||||
#define ICMPH_CODE_SET(hdr, c) ((hdr)->code = (c))
|
||||
|
||||
|
||||
@@ -35,10 +35,10 @@
|
||||
#ifndef __LWIP_IGMP_H__
|
||||
#define __LWIP_IGMP_H__
|
||||
|
||||
#include "lwip/opt.h"
|
||||
#include "lwip/ip_addr.h"
|
||||
#include "lwip/netif.h"
|
||||
#include "lwip/pbuf.h"
|
||||
#include "opt.h"
|
||||
#include "ip_addr.h"
|
||||
#include "netif.h"
|
||||
#include "pbuf.h"
|
||||
|
||||
#if LWIP_IGMP /* don't build if not configured for use in lwipopts.h */
|
||||
|
||||
|
||||
@@ -32,9 +32,9 @@
|
||||
#ifndef __LWIP_INET_H__
|
||||
#define __LWIP_INET_H__
|
||||
|
||||
#include "lwip/opt.h"
|
||||
#include "lwip/def.h"
|
||||
#include "lwip/ip_addr.h"
|
||||
#include "opt.h"
|
||||
#include "def.h"
|
||||
#include "ip_addr.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
||||
@@ -32,10 +32,10 @@
|
||||
#ifndef __LWIP_INET_CHKSUM_H__
|
||||
#define __LWIP_INET_CHKSUM_H__
|
||||
|
||||
#include "lwip/opt.h"
|
||||
#include "opt.h"
|
||||
|
||||
#include "lwip/pbuf.h"
|
||||
#include "lwip/ip_addr.h"
|
||||
#include "pbuf.h"
|
||||
#include "ip_addr.h"
|
||||
|
||||
/** Swap the bytes in an u16_t: much like htons() for little-endian */
|
||||
#ifndef SWAP_BYTES_IN_WORD
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
#ifndef __LWIP_INIT_H__
|
||||
#define __LWIP_INIT_H__
|
||||
|
||||
#include "lwip/opt.h"
|
||||
#include "opt.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
||||
@@ -32,13 +32,13 @@
|
||||
#ifndef __LWIP_IP_H__
|
||||
#define __LWIP_IP_H__
|
||||
|
||||
#include "lwip/opt.h"
|
||||
#include "opt.h"
|
||||
|
||||
#include "lwip/def.h"
|
||||
#include "lwip/pbuf.h"
|
||||
#include "lwip/ip_addr.h"
|
||||
#include "lwip/err.h"
|
||||
#include "lwip/netif.h"
|
||||
#include "def.h"
|
||||
#include "pbuf.h"
|
||||
#include "ip_addr.h"
|
||||
#include "err.h"
|
||||
#include "netif.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
||||
@@ -32,8 +32,8 @@
|
||||
#ifndef __LWIP_IP_ADDR_H__
|
||||
#define __LWIP_IP_ADDR_H__
|
||||
|
||||
#include "lwip/opt.h"
|
||||
#include "lwip/def.h"
|
||||
#include "opt.h"
|
||||
#include "def.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
||||
@@ -33,12 +33,12 @@
|
||||
#ifndef __LWIP_IP_FRAG_H__
|
||||
#define __LWIP_IP_FRAG_H__
|
||||
|
||||
#include "lwip/opt.h"
|
||||
#include "lwip/err.h"
|
||||
#include "lwip/pbuf.h"
|
||||
#include "lwip/netif.h"
|
||||
#include "lwip/ip_addr.h"
|
||||
#include "lwip/ip.h"
|
||||
#include "opt.h"
|
||||
#include "err.h"
|
||||
#include "pbuf.h"
|
||||
#include "netif.h"
|
||||
#include "ip_addr.h"
|
||||
#include "ip.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
#ifndef __LWIP_MEM_H__
|
||||
#define __LWIP_MEM_H__
|
||||
|
||||
#include "lwip/opt.h"
|
||||
#include "opt.h"
|
||||
#include "mem_manager.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
#ifndef __LWIP_MEMP_H__
|
||||
#define __LWIP_MEMP_H__
|
||||
|
||||
#include "lwip/opt.h"
|
||||
#include "opt.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
||||
@@ -32,9 +32,9 @@
|
||||
#ifndef __LWIP_NETBUF_H__
|
||||
#define __LWIP_NETBUF_H__
|
||||
|
||||
#include "lwip/opt.h"
|
||||
#include "lwip/pbuf.h"
|
||||
#include "lwip/ip_addr.h"
|
||||
#include "opt.h"
|
||||
#include "pbuf.h"
|
||||
#include "ip_addr.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
#ifndef __LWIP_NETDB_H__
|
||||
#define __LWIP_NETDB_H__
|
||||
|
||||
#include "lwip/opt.h"
|
||||
#include "opt.h"
|
||||
|
||||
#if LWIP_DNS && LWIP_SOCKET
|
||||
|
||||
|
||||
@@ -32,16 +32,16 @@
|
||||
#ifndef __LWIP_NETIF_H__
|
||||
#define __LWIP_NETIF_H__
|
||||
|
||||
#include "lwip/opt.h"
|
||||
#include "opt.h"
|
||||
|
||||
#define ENABLE_LOOPBACK (LWIP_NETIF_LOOPBACK || LWIP_HAVE_LOOPIF)
|
||||
|
||||
#include "lwip/err.h"
|
||||
#include "err.h"
|
||||
|
||||
#include "lwip/ip_addr.h"
|
||||
#include "ip_addr.h"
|
||||
|
||||
#include "lwip/def.h"
|
||||
#include "lwip/pbuf.h"
|
||||
#include "def.h"
|
||||
#include "pbuf.h"
|
||||
#if LWIP_DHCP
|
||||
struct dhcp;
|
||||
#endif
|
||||
@@ -143,15 +143,15 @@ struct netif {
|
||||
ip_addr_t gw;
|
||||
|
||||
/** This function is called by the network device driver
|
||||
* to pass a packet up the TCP/IP stack. 向IP层输入数据包*/
|
||||
* to pass a packet up the TCP/IP stack. ��IP��������ݰ�*/
|
||||
netif_input_fn input;
|
||||
/** This function is called by the IP module when it wants
|
||||
* to send a packet on the interface. This function typically
|
||||
* first resolves the hardware address, then sends the packet. 发送IP数据包*/
|
||||
* first resolves the hardware address, then sends the packet. ����IP��ݰ�*/
|
||||
netif_output_fn output;
|
||||
/** This function is called by the ARP module when it wants
|
||||
* to send a packet on the interface. This function outputs
|
||||
* the pbuf as-is on the link medium. 底层数据包发送*/
|
||||
* the pbuf as-is on the link medium. �ײ���ݰ���*/
|
||||
netif_linkoutput_fn linkoutput;
|
||||
#if LWIP_NETIF_STATUS_CALLBACK
|
||||
/** This function is called when the netif state is set to up or down
|
||||
@@ -164,7 +164,7 @@ struct netif {
|
||||
netif_status_callback_fn link_callback;
|
||||
#endif /* LWIP_NETIF_LINK_CALLBACK */
|
||||
/** This field can be set by the device driver and could point
|
||||
* to state information for the device. 自由设置字段,比如指向底层设备相关信息*/
|
||||
* to state information for the device. ���������ֶΣ�����ָ��ײ��豸�����Ϣ*/
|
||||
void *state;
|
||||
#if LWIP_DHCP
|
||||
/** the DHCP client state information for this netif */
|
||||
@@ -178,17 +178,17 @@ struct netif {
|
||||
/* the hostname for this netif, NULL is a valid value */
|
||||
char* hostname;
|
||||
#endif /* LWIP_NETIF_HOSTNAME */
|
||||
/** maximum transfer unit (in bytes) 该接口允许的最大数据包长度,多是1500*/
|
||||
/** maximum transfer unit (in bytes) �ýӿ�����������ݰ�ȣ�����1500*/
|
||||
u16_t mtu;
|
||||
/** number of bytes used in hwaddr该接口物理地址长度 */
|
||||
/** number of bytes used in hwaddr�ýӿ������ַ���� */
|
||||
u8_t hwaddr_len;
|
||||
/** link level hardware address of this interface 该接口物理地址*/
|
||||
/** link level hardware address of this interface �ýӿ������ַ*/
|
||||
u8_t hwaddr[NETIF_MAX_HWADDR_LEN];
|
||||
/** flags (see NETIF_FLAG_ above) 该接口状态、属性字段*/
|
||||
/** flags (see NETIF_FLAG_ above) �ýӿ�״̬�������ֶ�*/
|
||||
u8_t flags;
|
||||
/** descriptive abbreviation 该接口的名字*/
|
||||
/** descriptive abbreviation �ýӿڵ�����*/
|
||||
char name[2];
|
||||
/** number of this interface 该接口的编号*/
|
||||
/** number of this interface �ýӿڵı��*/
|
||||
u8_t num;
|
||||
#if LWIP_SNMP
|
||||
/** link type (from "snmp_ifType" enum from snmp.h) */
|
||||
@@ -216,9 +216,9 @@ struct netif {
|
||||
u8_t *addr_hint;
|
||||
#endif /* LWIP_NETIF_HWADDRHINT */
|
||||
#if ENABLE_LOOPBACK
|
||||
/* List of packets to be queued for ourselves. 指向发送给自己的数据包的pbuf*/
|
||||
struct pbuf *loop_first;//第一个
|
||||
struct pbuf *loop_last;//最后一个
|
||||
/* List of packets to be queued for ourselves. ָ�����Լ�����ݰ��pbuf*/
|
||||
struct pbuf *loop_first;//��һ��
|
||||
struct pbuf *loop_last;//���һ��
|
||||
#if LWIP_LOOPBACK_MAX_PBUFS
|
||||
u16_t loop_cnt_current;
|
||||
#endif /* LWIP_LOOPBACK_MAX_PBUFS */
|
||||
|
||||
@@ -28,14 +28,14 @@
|
||||
#ifndef __LWIP_NETIFAPI_H__
|
||||
#define __LWIP_NETIFAPI_H__
|
||||
|
||||
#include "lwip/opt.h"
|
||||
#include "opt.h"
|
||||
|
||||
#if LWIP_NETIF_API /* don't build if not configured for use in lwipopts.h */
|
||||
|
||||
#include "lwip/sys.h"
|
||||
#include "lwip/netif.h"
|
||||
#include "lwip/dhcp.h"
|
||||
#include "lwip/autoip.h"
|
||||
#include "sys.h"
|
||||
#include "netif.h"
|
||||
#include "dhcp.h"
|
||||
#include "autoip.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
||||
@@ -42,8 +42,8 @@
|
||||
* Include user defined options first. Anything not defined in these files
|
||||
* will be set to standard values. Override anything you dont like!
|
||||
*/
|
||||
#include "include/lwipopts.h"
|
||||
#include "lwip/debug.h"
|
||||
#include "../include/lwipopts.h"
|
||||
#include "../lwip/debug.h"
|
||||
|
||||
/*
|
||||
-----------------------------------------------
|
||||
|
||||
@@ -33,8 +33,8 @@
|
||||
#ifndef __LWIP_PBUF_H__
|
||||
#define __LWIP_PBUF_H__
|
||||
|
||||
#include "lwip/opt.h"
|
||||
#include "lwip/err.h"
|
||||
#include "opt.h"
|
||||
#include "err.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
||||
@@ -32,14 +32,14 @@
|
||||
#ifndef __LWIP_RAW_H__
|
||||
#define __LWIP_RAW_H__
|
||||
|
||||
#include "lwip/opt.h"
|
||||
#include "opt.h"
|
||||
|
||||
#if LWIP_RAW /* don't build if not configured for use in lwipopts.h */
|
||||
|
||||
#include "lwip/pbuf.h"
|
||||
#include "lwip/def.h"
|
||||
#include "lwip/ip.h"
|
||||
#include "lwip/ip_addr.h"
|
||||
#include "pbuf.h"
|
||||
#include "def.h"
|
||||
#include "ip.h"
|
||||
#include "ip_addr.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
#ifndef __SIO_H__
|
||||
#define __SIO_H__
|
||||
|
||||
#include "lwip/arch.h"
|
||||
#include "arch.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
||||
@@ -33,13 +33,13 @@
|
||||
#ifndef __LWIP_SNMP_H__
|
||||
#define __LWIP_SNMP_H__
|
||||
|
||||
#include "lwip/opt.h"
|
||||
#include "opt.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "lwip/ip_addr.h"
|
||||
#include "ip_addr.h"
|
||||
|
||||
struct udp_pcb;
|
||||
struct netif;
|
||||
|
||||
@@ -35,10 +35,10 @@
|
||||
#ifndef __LWIP_SNMP_ASN1_H__
|
||||
#define __LWIP_SNMP_ASN1_H__
|
||||
|
||||
#include "lwip/opt.h"
|
||||
#include "lwip/err.h"
|
||||
#include "lwip/pbuf.h"
|
||||
#include "lwip/snmp.h"
|
||||
#include "opt.h"
|
||||
#include "err.h"
|
||||
#include "pbuf.h"
|
||||
#include "snmp.h"
|
||||
|
||||
#if LWIP_SNMP
|
||||
|
||||
|
||||
@@ -35,11 +35,11 @@
|
||||
#ifndef __LWIP_SNMP_MSG_H__
|
||||
#define __LWIP_SNMP_MSG_H__
|
||||
|
||||
#include "lwip/opt.h"
|
||||
#include "lwip/snmp.h"
|
||||
#include "lwip/snmp_structs.h"
|
||||
#include "lwip/ip_addr.h"
|
||||
#include "lwip/err.h"
|
||||
#include "opt.h"
|
||||
#include "snmp.h"
|
||||
#include "snmp_structs.h"
|
||||
#include "ip_addr.h"
|
||||
#include "err.h"
|
||||
|
||||
#if LWIP_SNMP
|
||||
|
||||
|
||||
@@ -37,11 +37,11 @@
|
||||
#ifndef __LWIP_SNMP_STRUCTS_H__
|
||||
#define __LWIP_SNMP_STRUCTS_H__
|
||||
|
||||
#include "lwip/opt.h"
|
||||
#include "opt.h"
|
||||
|
||||
#if LWIP_SNMP /* don't build if not configured for use in lwipopts.h */
|
||||
|
||||
#include "lwip/snmp.h"
|
||||
#include "snmp.h"
|
||||
|
||||
#if SNMP_PRIVATE_MIB
|
||||
/* When using a private MIB, you have to create a file 'private_mib.h' that contains
|
||||
|
||||
@@ -34,14 +34,14 @@
|
||||
#ifndef __LWIP_SOCKETS_H__
|
||||
#define __LWIP_SOCKETS_H__
|
||||
|
||||
#include "lwip/opt.h"
|
||||
#include "opt.h"
|
||||
|
||||
#if LWIP_SOCKET /* don't build if not configured for use in lwipopts.h */
|
||||
|
||||
#include <stddef.h> /* for size_t */
|
||||
|
||||
#include "lwip/ip_addr.h"
|
||||
#include "lwip/inet.h"
|
||||
#include "ip_addr.h"
|
||||
#include "inet.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
||||
@@ -32,10 +32,10 @@
|
||||
#ifndef __LWIP_STATS_H__
|
||||
#define __LWIP_STATS_H__
|
||||
|
||||
#include "lwip/opt.h"
|
||||
#include "opt.h"
|
||||
|
||||
#include "lwip/mem.h"
|
||||
#include "lwip/memp.h"
|
||||
#include "mem.h"
|
||||
#include "memp.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
#ifndef __LWIP_SYS_H__
|
||||
#define __LWIP_SYS_H__
|
||||
|
||||
#include "lwip/opt.h"
|
||||
#include "opt.h"
|
||||
|
||||
#include "eagle_soc.h"
|
||||
|
||||
|
||||
@@ -32,16 +32,16 @@
|
||||
#ifndef __LWIP_TCP_H__
|
||||
#define __LWIP_TCP_H__
|
||||
|
||||
#include "lwip/opt.h"
|
||||
#include "opt.h"
|
||||
|
||||
#if LWIP_TCP /* don't build if not configured for use in lwipopts.h */
|
||||
|
||||
#include "lwip/sys.h"
|
||||
#include "lwip/mem.h"
|
||||
#include "lwip/pbuf.h"
|
||||
#include "lwip/ip.h"
|
||||
#include "lwip/icmp.h"
|
||||
#include "lwip/err.h"
|
||||
#include "sys.h"
|
||||
#include "mem.h"
|
||||
#include "pbuf.h"
|
||||
#include "ip.h"
|
||||
#include "icmp.h"
|
||||
#include "err.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
||||
@@ -32,17 +32,17 @@
|
||||
#ifndef __LWIP_TCP_IMPL_H__
|
||||
#define __LWIP_TCP_IMPL_H__
|
||||
|
||||
#include "lwip/opt.h"
|
||||
#include "opt.h"
|
||||
|
||||
#if LWIP_TCP /* don't build if not configured for use in lwipopts.h */
|
||||
|
||||
#include "lwip/tcp.h"
|
||||
#include "lwip/sys.h"
|
||||
#include "lwip/mem.h"
|
||||
#include "lwip/pbuf.h"
|
||||
#include "lwip/ip.h"
|
||||
#include "lwip/icmp.h"
|
||||
#include "lwip/err.h"
|
||||
#include "tcp.h"
|
||||
#include "sys.h"
|
||||
#include "mem.h"
|
||||
#include "pbuf.h"
|
||||
#include "ip.h"
|
||||
#include "icmp.h"
|
||||
#include "err.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@@ -156,14 +156,14 @@ u32_t tcp_update_rcv_ann_wnd(struct tcp_pcb *pcb)ICACHE_FLASH_ATTR;
|
||||
#endif
|
||||
PACK_STRUCT_BEGIN
|
||||
struct tcp_hdr {
|
||||
PACK_STRUCT_FIELD(u16_t src); //源端口
|
||||
PACK_STRUCT_FIELD(u16_t dest); //目的端口
|
||||
PACK_STRUCT_FIELD(u32_t seqno); //序号
|
||||
PACK_STRUCT_FIELD(u32_t ackno); //应答序号
|
||||
PACK_STRUCT_FIELD(u16_t _hdrlen_rsvd_flags);//首部长度+保留位+标志位
|
||||
PACK_STRUCT_FIELD(u16_t wnd); //窗口大小
|
||||
PACK_STRUCT_FIELD(u16_t chksum); //校验和
|
||||
PACK_STRUCT_FIELD(u16_t urgp); //紧急指针
|
||||
PACK_STRUCT_FIELD(u16_t src); //Դ�˿�
|
||||
PACK_STRUCT_FIELD(u16_t dest); //Ŀ�Ķ˿�
|
||||
PACK_STRUCT_FIELD(u32_t seqno); //���
|
||||
PACK_STRUCT_FIELD(u32_t ackno); //Ӧ�����
|
||||
PACK_STRUCT_FIELD(u16_t _hdrlen_rsvd_flags);//�ײ�����+����λ+��־λ
|
||||
PACK_STRUCT_FIELD(u16_t wnd); //���ڴ�С
|
||||
PACK_STRUCT_FIELD(u16_t chksum); //���
|
||||
PACK_STRUCT_FIELD(u16_t urgp); //����ָ��
|
||||
} PACK_STRUCT_STRUCT;
|
||||
PACK_STRUCT_END
|
||||
#ifdef PACK_STRUCT_USE_INCLUDES
|
||||
|
||||
@@ -32,17 +32,17 @@
|
||||
#ifndef __LWIP_TCPIP_H__
|
||||
#define __LWIP_TCPIP_H__
|
||||
|
||||
#include "lwip/opt.h"
|
||||
#include "opt.h"
|
||||
|
||||
#if !NO_SYS /* don't build if not configured for use in lwipopts.h */
|
||||
|
||||
#include "lwip/api_msg.h"
|
||||
#include "lwip/netifapi.h"
|
||||
#include "lwip/pbuf.h"
|
||||
#include "lwip/api.h"
|
||||
#include "lwip/sys.h"
|
||||
#include "lwip/timers.h"
|
||||
#include "lwip/netif.h"
|
||||
#include "api_msg.h"
|
||||
#include "netifapi.h"
|
||||
#include "pbuf.h"
|
||||
#include "api.h"
|
||||
#include "sys.h"
|
||||
#include "timers.h"
|
||||
#include "netif.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
||||
@@ -33,15 +33,15 @@
|
||||
#ifndef __LWIP_TIMERS_H__
|
||||
#define __LWIP_TIMERS_H__
|
||||
|
||||
#include "lwip/opt.h"
|
||||
#include "opt.h"
|
||||
|
||||
/* Timers are not supported when NO_SYS==1 and NO_SYS_NO_TIMERS==1 */
|
||||
#define LWIP_TIMERS (!NO_SYS || (NO_SYS && !NO_SYS_NO_TIMERS))
|
||||
|
||||
#if LWIP_TIMERS
|
||||
|
||||
#include "lwip/err.h"
|
||||
#include "lwip/sys.h"
|
||||
#include "err.h"
|
||||
#include "sys.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
||||
@@ -32,14 +32,14 @@
|
||||
#ifndef __LWIP_UDP_H__
|
||||
#define __LWIP_UDP_H__
|
||||
|
||||
#include "lwip/opt.h"
|
||||
#include "opt.h"
|
||||
|
||||
#if LWIP_UDP /* don't build if not configured for use in lwipopts.h */
|
||||
|
||||
#include "lwip/pbuf.h"
|
||||
#include "lwip/netif.h"
|
||||
#include "lwip/ip_addr.h"
|
||||
#include "lwip/ip.h"
|
||||
#include "pbuf.h"
|
||||
#include "netif.h"
|
||||
#include "ip_addr.h"
|
||||
#include "ip.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
||||
@@ -60,9 +60,6 @@ MyMessage lightMsg(0, V_LIGHT);
|
||||
*/
|
||||
void setup()
|
||||
{
|
||||
// Initialize library and add callback for incoming messages (signing is required)
|
||||
setIncomingCallback(incomingMessage);
|
||||
|
||||
// Register the LED Dimmable Light with the gateway
|
||||
present( 0, S_DIMMER );
|
||||
|
||||
@@ -80,7 +77,7 @@ void loop()
|
||||
|
||||
|
||||
|
||||
void incomingMessage(const MyMessage &message) {
|
||||
void receive(const MyMessage &message) {
|
||||
if (message.type == V_LIGHT || message.type == V_DIMMER) {
|
||||
|
||||
// Retrieve the power or dim level from the incoming request message
|
||||
|
||||
@@ -57,9 +57,6 @@ MyMessage dimmerMsg(CHILD_ID_LIGHT, V_DIMMER);
|
||||
|
||||
void setup()
|
||||
{
|
||||
// Initialize library and add callback for incoming messages (signing is required)
|
||||
setIncomingCallback(incomingMessage);
|
||||
|
||||
// Send the Sketch Version Information to the Gateway
|
||||
sendSketchInfo(SN, SV);
|
||||
|
||||
@@ -86,7 +83,7 @@ void loop()
|
||||
{
|
||||
}
|
||||
|
||||
void incomingMessage(const MyMessage &message)
|
||||
void receive(const MyMessage &message)
|
||||
{
|
||||
if (message.type == V_LIGHT) {
|
||||
Serial.println( "V_LIGHT command received..." );
|
||||
|
||||
+1
-4
@@ -85,9 +85,6 @@ Bounce debouncer = Bounce();
|
||||
|
||||
void setup()
|
||||
{
|
||||
// Initialize library and add callback for incoming messages (signing is required)
|
||||
setIncomingCallback(incomingMessage);
|
||||
|
||||
// Set knob button pin as input (with debounce)
|
||||
pinMode(KNOB_BUTTON_PIN, INPUT);
|
||||
digitalWrite(KNOB_BUTTON_PIN, HIGH);
|
||||
@@ -124,7 +121,7 @@ void loop()
|
||||
fadeStep();
|
||||
}
|
||||
|
||||
void incomingMessage(const MyMessage &message)
|
||||
void receive(const MyMessage &message)
|
||||
{
|
||||
if (message.type == V_LIGHT) {
|
||||
// Incoming on/off command sent from controller ("1" or "0")
|
||||
|
||||
@@ -67,9 +67,6 @@ MyMessage pcMsg(CHILD_ID,V_VAR1);
|
||||
|
||||
void setup()
|
||||
{
|
||||
// Initialize library and add callback for incoming messages (signing is required)
|
||||
setIncomingCallback(incomingMessage);
|
||||
|
||||
// Send the sketch version information to the gateway and Controller
|
||||
sendSketchInfo("Energy Meter", "1.0");
|
||||
|
||||
@@ -124,7 +121,7 @@ void loop()
|
||||
}
|
||||
}
|
||||
|
||||
void incomingMessage(const MyMessage &message) {
|
||||
void receive(const MyMessage &message) {
|
||||
if (message.type==V_VAR1) {
|
||||
pulseCount = oldPulseCount = message.getLong();
|
||||
Serial.print("Received last pulse count from gw:");
|
||||
|
||||
@@ -64,64 +64,78 @@
|
||||
*
|
||||
* 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"
|
||||
|
||||
// Enable debug prints to serial monitor
|
||||
#define MY_DEBUG
|
||||
|
||||
// Enable and select radio type (if attached)
|
||||
#define MY_RADIO_NRF24
|
||||
//#define MY_RADIO_RFM69
|
||||
|
||||
// Gateway always enabled for ESP8266 by default
|
||||
//#define MY_GATEWAY_ESP8266
|
||||
|
||||
// Enable to use UDP
|
||||
#define MY_USE_UDP
|
||||
|
||||
#define MY_IP_ADDRESS 192,168,178,66 // If this is disabled, DHCP is used to retrieve address
|
||||
// Renewal period if using DHCP
|
||||
//#define MY_IP_RENEWAL_INTERVAL 60000
|
||||
// The port to keep open on node server mode / or port to contact in client mode
|
||||
#define MY_PORT 5003
|
||||
|
||||
// Controller ip address (enables client mode). Undefine this to act as sever.
|
||||
#define MY_CONTROLLER_IP_ADDRESS 192, 168, 178, 254
|
||||
|
||||
// The MAC address can be anything you want but should be unique on your network.
|
||||
// Newer boards have a MAC address printed on the underside of the PCB, which you can (optionally) use.
|
||||
// Note that most of the Ardunio examples use "DEAD BEEF FEED" for the MAC address.
|
||||
#define MY_MAC_ADDRESS 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
|
||||
|
||||
// Flash leds on rx/tx/err
|
||||
#define MY_LEDS_BLINKING_FEATURE
|
||||
// Set blinking period
|
||||
#define MY_DEFAULT_LED_BLINK_PERIOD 300
|
||||
|
||||
// Enable inclusion mode
|
||||
#define MY_INCLUSION_MODE_FEATURE
|
||||
// Enable Inclusion mode button on gateway
|
||||
#define MY_INCLUSION_BUTTON_FEATURE
|
||||
// Set inclusion mode duration (in seconds)
|
||||
#define MY_INCLUSION_MODE_DURATION 60
|
||||
// Digital pin used for inclusion mode button
|
||||
#define MY_INCLUSION_MODE_BUTTON_PIN 3
|
||||
|
||||
#define MY_DEFAULT_ERR_LED_PIN 7 // Error led pin
|
||||
#define MY_DEFAULT_RX_LED_PIN 8 // Receive led pin
|
||||
#define MY_DEFAULT_TX_LED_PIN 9 // the PCB, on board LED
|
||||
|
||||
|
||||
// NEW
|
||||
#define MY_ESP8266_MAX_CLIENTS 5 // how many clients should be able to telnet to this ESP8266
|
||||
#define MY_ESP8266_SSID "MySSID"
|
||||
#define MY_ESP8266_PASSWORD "MyVerySecretPassword"
|
||||
|
||||
|
||||
|
||||
#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
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char string[MAX_RECEIVE_LENGTH];
|
||||
uint8_t idx;
|
||||
} inputBuffer;
|
||||
|
||||
|
||||
#include <MySensor.h>
|
||||
//#include <stdarg.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
|
||||
#define MAX_SRV_CLIENTS 5 // how many clients should be able to telnet to this ESP8266
|
||||
@@ -155,7 +169,7 @@ void output(const char *fmt, ... )
|
||||
|
||||
void setup()
|
||||
{
|
||||
// Setup console
|
||||
/* // Setup console
|
||||
hw_init();
|
||||
|
||||
Serial.println(); Serial.println();
|
||||
@@ -175,17 +189,16 @@ void setup()
|
||||
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);
|
||||
begin(incomingMessage, 0, true, 0);
|
||||
|
||||
// start listening for clients
|
||||
server.begin();
|
||||
server.setNoDelay(true);
|
||||
server.setNoDelay(true); */
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
gw.process();
|
||||
|
||||
/*
|
||||
checkButtonTriggeredInclusion();
|
||||
checkInclusionFinished();
|
||||
|
||||
@@ -258,7 +271,7 @@ void loop() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -110,9 +110,6 @@
|
||||
#define MY_DEFAULT_RX_LED_PIN 8 // Receive led pin
|
||||
#define MY_DEFAULT_TX_LED_PIN 9 // the PCB, on board LED
|
||||
|
||||
#define MY_RADIO_CE_PIN 5 // radio chip enable
|
||||
#define MY_RADIO_SPI_SS_PIN 6 // radio SPI serial select
|
||||
|
||||
#include <MySensor.h>
|
||||
|
||||
|
||||
|
||||
@@ -56,7 +56,6 @@ void setup()
|
||||
{
|
||||
irrecv.enableIRIn(); // Start the ir receiver
|
||||
decoder.UseExtnBuf(Buffer);
|
||||
setIncomingCallback(incomingMessage);
|
||||
|
||||
// Send the sketch version information to the gateway and Controller
|
||||
sendSketchInfo("IR Sensor", "1.0");
|
||||
@@ -82,7 +81,7 @@ void loop()
|
||||
|
||||
|
||||
|
||||
void incomingMessage(const MyMessage &message) {
|
||||
void receive(const MyMessage &message) {
|
||||
// We only expect one type of message from controller. But we better check anyway.
|
||||
if (message.type==V_LIGHT) {
|
||||
int incomingRelayStatus = message.getInt();
|
||||
|
||||
@@ -206,7 +206,6 @@ void setup()
|
||||
lastTimeRun = lastTimeRun | loadState(i + 1); // assemble 4 bytes into an ussigned long epoch timestamp
|
||||
}
|
||||
}
|
||||
setIncomingCallback(getVariables);
|
||||
sendSketchInfo(SKETCH_NAME, SKETCH_VERSION);
|
||||
for (byte i = 0; i <= NUMBER_OF_VALVES; i++)
|
||||
{
|
||||
@@ -225,7 +224,7 @@ void setup()
|
||||
int clockCounter = 0;
|
||||
while (timeStatus() == timeNotSet && clockCounter < 21)
|
||||
{
|
||||
requestTime(receiveTime);
|
||||
requestTime();
|
||||
DEBUG_PRINTLN(F("Requesting time from Gateway:"));
|
||||
wait(1000);
|
||||
lcd.print(".");
|
||||
@@ -533,7 +532,7 @@ void slowToggleLED ()
|
||||
}
|
||||
}
|
||||
//
|
||||
void getVariables(const MyMessage &message)
|
||||
void receive(const MyMessage &message)
|
||||
{
|
||||
boolean zoneTimeUpdate = false;
|
||||
if (message.isAck())
|
||||
@@ -835,7 +834,7 @@ void updateClock()
|
||||
lcd.setCursor(15, 0);
|
||||
lcd.write(byte(0));
|
||||
clockUpdating = true;
|
||||
requestTime(receiveTime);
|
||||
requestTime();
|
||||
lastVeraGetTime = millis();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -333,8 +333,6 @@ void setup()
|
||||
// Random SEED
|
||||
randomSeed(analogRead(0));
|
||||
|
||||
// Start the gateway
|
||||
setIncomingCallback(incomingMessage);
|
||||
wait(LONG_WAIT);
|
||||
Serial.println("GW Started");
|
||||
|
||||
@@ -574,7 +572,7 @@ void loop()
|
||||
|
||||
// Request time
|
||||
Serial.println("Request Time");
|
||||
requestTime(receiveTime);
|
||||
requestTime();
|
||||
wait(LONG_WAIT);
|
||||
|
||||
//Read Sensors
|
||||
@@ -1196,7 +1194,7 @@ void custom(){
|
||||
#endif
|
||||
|
||||
|
||||
void incomingMessage(const MyMessage &message) {
|
||||
void receive(const MyMessage &message) {
|
||||
switch (message.type) {
|
||||
#ifdef ID_S_ARMED
|
||||
case V_ARMED:
|
||||
|
||||
@@ -29,8 +29,6 @@ MyMessage mPing(CHILD, V_VAR1); //Ping message
|
||||
MyMessage mPong(CHILD, V_VAR2); //Pong message
|
||||
|
||||
void setup() {
|
||||
setIncomingCallback(incomingMessage);
|
||||
|
||||
present(CHILD, S_CUSTOM); //
|
||||
|
||||
sendSketchInfo( nodeTypeAsCharRepresentation( getNodeId() ), VSN );
|
||||
@@ -63,7 +61,7 @@ void loop() {
|
||||
}
|
||||
}
|
||||
|
||||
void incomingMessage(const MyMessage &message) {
|
||||
void receive(const MyMessage &message) {
|
||||
|
||||
LOG(F("Received %s from %s\n"), msgTypeAsCharRepresentation((mysensor_data)message.type), nodeTypeAsCharRepresentation(message.sender));
|
||||
|
||||
|
||||
@@ -96,9 +96,6 @@ void setup() {
|
||||
// configure board to read RFID tags
|
||||
nfc.SAMConfig();
|
||||
|
||||
// Add callback for incoming messages
|
||||
setIncomingCallback(incomingMessage);
|
||||
|
||||
sendSketchInfo("RFID Lock", "1.0");
|
||||
present(CHILD_ID, S_LOCK);
|
||||
|
||||
@@ -169,7 +166,7 @@ void setLockState(bool state, bool doSend){
|
||||
lockStatus = state;
|
||||
}
|
||||
|
||||
void incomingMessage(const MyMessage &message) {
|
||||
void receive(const MyMessage &message) {
|
||||
// We only expect one type of message from controller. But we better check anyway.
|
||||
if (message.type==V_LOCK_STATUS) {
|
||||
// Change relay state
|
||||
|
||||
@@ -62,9 +62,6 @@ int isShow;
|
||||
|
||||
void setup()
|
||||
{
|
||||
// Add callback for incoming messages
|
||||
setIncomingCallback(incomingMessage);
|
||||
|
||||
// Present sketch (name, version)
|
||||
sendSketchInfo(SN, SV);
|
||||
|
||||
@@ -130,7 +127,7 @@ void loop()
|
||||
}
|
||||
|
||||
|
||||
void incomingMessage(const MyMessage &message)
|
||||
void receive(const MyMessage &message)
|
||||
{
|
||||
if (message.isAck())
|
||||
{
|
||||
|
||||
@@ -145,9 +145,6 @@ void setup()
|
||||
pinMode(ledPin, OUTPUT);
|
||||
digitalWrite(ledPin, HIGH);
|
||||
//
|
||||
//Let's get the controller talking to the Arduino
|
||||
setIncomingCallback(getVariables);
|
||||
|
||||
sendSketchInfo(SKETCH_NAME, SKETCH_VERSION);
|
||||
wait(DWELL_TIME);
|
||||
present(CHILD_ID_RAIN_LOG, S_RAIN);
|
||||
@@ -161,7 +158,7 @@ void setup()
|
||||
unsigned long functionTimeout = millis();
|
||||
while (timeStatus() == timeNotSet && millis() - functionTimeout < 30000UL)
|
||||
{
|
||||
requestTime(receiveTime);
|
||||
requestTime();
|
||||
DEBUG_PRINTLN(F("Getting Time"));
|
||||
wait(1000); // call once per second
|
||||
DEBUG_PRINTLN(F("."));
|
||||
@@ -322,7 +319,7 @@ void loop()
|
||||
DEBUG_PRINTLN(eepromIndex);
|
||||
saveState(eepromIndex, 0xFE);
|
||||
saveState(eepromIndex + 1, 0xFE);
|
||||
requestTime(receiveTime); // sync the time every hour
|
||||
requestTime(); // sync the time every hour
|
||||
wait(DWELL_TIME);
|
||||
transmitRainData();
|
||||
rainRate = 0;
|
||||
@@ -529,7 +526,7 @@ void transmitRainData(void)
|
||||
wait(DWELL_TIME);
|
||||
}
|
||||
|
||||
void getVariables(const MyMessage &message)
|
||||
void receive(const MyMessage &message)
|
||||
{
|
||||
if (message.sensor == CHILD_ID_RAIN_LOG)
|
||||
{
|
||||
|
||||
+2
-2
@@ -68,7 +68,7 @@ void setup()
|
||||
setSyncProvider(RTC.get);
|
||||
|
||||
// Request latest time from controller at startup
|
||||
requestTime(receiveTime);
|
||||
requestTime();
|
||||
|
||||
// initialize the lcd for 16 chars 2 lines and turn on backlight
|
||||
lcd.begin(16,2);
|
||||
@@ -93,7 +93,7 @@ void loop()
|
||||
|| (timeReceived && (now-lastRequest) > (60UL*1000UL*60UL))) {
|
||||
// Request time from controller.
|
||||
Serial.println("requesting time");
|
||||
requestTime(receiveTime);
|
||||
requestTime();
|
||||
lastRequest = now;
|
||||
}
|
||||
|
||||
|
||||
@@ -46,9 +46,6 @@
|
||||
|
||||
void setup()
|
||||
{
|
||||
// Initialize library and add callback for incoming messages
|
||||
setIncomingCallback(incomingMessage);
|
||||
|
||||
// Send the sketch version information to the gateway and Controller
|
||||
sendSketchInfo("Relay", "1.0");
|
||||
|
||||
@@ -69,7 +66,7 @@ void loop()
|
||||
|
||||
}
|
||||
|
||||
void incomingMessage(const MyMessage &message) {
|
||||
void receive(const MyMessage &message) {
|
||||
// We only expect one type of message from controller. But we better check anyway.
|
||||
if (message.type==V_LIGHT) {
|
||||
// Change relay state
|
||||
|
||||
@@ -56,8 +56,6 @@ MyMessage msg(CHILD_ID,V_LIGHT);
|
||||
|
||||
void setup()
|
||||
{
|
||||
setIncomingCallback(incomingMessage);
|
||||
|
||||
// Send the sketch version information to the gateway and Controller
|
||||
sendSketchInfo("Relay & Button", "1.0");
|
||||
|
||||
@@ -98,7 +96,7 @@ void loop()
|
||||
oldValue = value;
|
||||
}
|
||||
|
||||
void incomingMessage(const MyMessage &message) {
|
||||
void receive(const MyMessage &message) {
|
||||
// We only expect one type of message from controller. But we better check anyway.
|
||||
if (message.isAck()) {
|
||||
Serial.println("This is an ack from gateway");
|
||||
|
||||
@@ -98,8 +98,6 @@ void setup() {
|
||||
pinMode(programButton, INPUT);
|
||||
digitalWrite(programButton, HIGH); // Enable internal pull up
|
||||
|
||||
setIncomingCallback(incomingMessage);
|
||||
|
||||
sendSketchInfo("Secret Knock", "1.0");
|
||||
present(CHILD_ID, S_LOCK);
|
||||
|
||||
@@ -365,7 +363,7 @@ void chirp(int playTime, int delayTime){
|
||||
|
||||
|
||||
|
||||
void incomingMessage(const MyMessage &message) {
|
||||
void receive(const MyMessage &message) {
|
||||
// We only expect one type of message from controller. But we better check anyway.
|
||||
if (message.type==V_LOCK_STATUS) {
|
||||
// Change relay state
|
||||
|
||||
@@ -62,11 +62,8 @@
|
||||
#define LOCK_LOCK 1 // GPIO value to write to lock attached lock
|
||||
#define LOCK_UNLOCK 0 // GPIO value to write to unlock attached lock
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
// Add callback for incoming messages (signing is required)
|
||||
setIncomingCallback(incomingMessage);
|
||||
// Send the sketch version information to the gateway and Controller
|
||||
sendSketchInfo("Secure Lock", "1.0");
|
||||
|
||||
@@ -85,7 +82,7 @@ void loop()
|
||||
{
|
||||
}
|
||||
|
||||
void incomingMessage(const MyMessage &message) {
|
||||
void receive(const MyMessage &message) {
|
||||
// We only expect one type of message from controller. But we better check anyway.
|
||||
if (message.type==V_LOCK_STATUS && message.sensor<=NOF_LOCKS) {
|
||||
// Change relay state
|
||||
|
||||
@@ -55,9 +55,6 @@ bool attachedServo = false;
|
||||
|
||||
void setup()
|
||||
{
|
||||
// Attach method for incoming messages
|
||||
setIncomingCallback(incomingMessage);
|
||||
|
||||
// Send the sketch version information to the gateway and Controller
|
||||
sendSketchInfo("Servo", "1.0");
|
||||
|
||||
@@ -76,7 +73,7 @@ void loop()
|
||||
}
|
||||
}
|
||||
|
||||
void incomingMessage(const MyMessage &message) {
|
||||
void receive(const MyMessage &message) {
|
||||
myservo.attach(SERVO_DIGITAL_OUT_PIN);
|
||||
attachedServo = true;
|
||||
if (message.type==V_DIMMER) { // This could be M_ACK_VARIABLE or M_SET_VARIABLE
|
||||
|
||||
@@ -44,7 +44,7 @@ void setup()
|
||||
sendSketchInfo("Clock", "1.0");
|
||||
|
||||
// Request time from controller.
|
||||
requestTime(receiveTime);
|
||||
requestTime();
|
||||
}
|
||||
|
||||
// This is called when a new time value was received
|
||||
@@ -64,7 +64,7 @@ void loop()
|
||||
|| (timeReceived && (now-lastRequest) > (60UL*1000UL*60UL))) {
|
||||
// Request time from controller.
|
||||
Serial.println("requesting time");
|
||||
requestTime(receiveTime);
|
||||
requestTime();
|
||||
lastRequest = now;
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -131,7 +131,7 @@ void setup()
|
||||
sendSketchInfo("Scene Ctrl", "1.0");
|
||||
present(CHILD_ID, S_SCENE_CONTROLLER);
|
||||
// Request time from controller.
|
||||
requestTime(receiveTime);
|
||||
requestTime();
|
||||
}
|
||||
|
||||
|
||||
@@ -170,7 +170,7 @@ void loop()
|
||||
|| (timeReceived && now-lastRequest > (unsigned long)60*1000*60)) {
|
||||
// Request time from controller.
|
||||
Serial.println("requesting time");
|
||||
requestTime(receiveTime);
|
||||
requestTime();
|
||||
lastRequest = now;
|
||||
}
|
||||
|
||||
|
||||
@@ -76,8 +76,6 @@ unsigned long lastPulse =0;
|
||||
|
||||
void setup()
|
||||
{
|
||||
setIncomingCallback(incomingMessage);
|
||||
|
||||
// initialize our digital pins internal pullup resistor so one pulse switches from high to low (less distortion)
|
||||
pinMode(DIGITAL_INPUT_SENSOR, INPUT_PULLUP);
|
||||
|
||||
@@ -156,7 +154,7 @@ void loop()
|
||||
}
|
||||
}
|
||||
|
||||
void incomingMessage(const MyMessage &message) {
|
||||
void receive(const MyMessage &message) {
|
||||
if (message.type==V_VAR1) {
|
||||
unsigned long gwPulseCount=message.getULong();
|
||||
pulseCount += gwPulseCount;
|
||||
|
||||
@@ -19,6 +19,11 @@ requestTime KEYWORD2
|
||||
saveState KEYWORD2
|
||||
loadState KEYWORD2
|
||||
wait KEYWORD2
|
||||
receive KEYWORD2
|
||||
receiveTime KEYWORD2
|
||||
loop KEYWORD2
|
||||
setup KEYWORD2
|
||||
presentation KEYWORD2
|
||||
|
||||
######################################
|
||||
# Constants (LITERAL1)
|
||||
|
||||
Reference in New Issue
Block a user