MySensors Library & Examples  2.3.2
GatewayW5100.ino
1 /*
2  * The MySensors Arduino library handles the wireless radio link and protocol
3  * between your home built sensors/actuators and HA controller of choice.
4  * The sensors forms a self healing radio network with optional repeaters. Each
5  * repeater and gateway builds a routing tables in EEPROM which keeps track of the
6  * network topology allowing messages to be routed to nodes.
7  *
8  * Created by Henrik Ekblad <[email protected]>
9  * Copyright (C) 2013-2019 Sensnology AB
10  * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors
11  *
12  * Documentation: http://www.mysensors.org
13  * Support Forum: http://forum.mysensors.org
14  *
15  * This program is free software; you can redistribute it and/or
16  * modify it under the terms of the GNU General Public License
17  * version 2 as published by the Free Software Foundation.
18  *
19  *******************************
20  *
21  * REVISION HISTORY
22  * Version 1.0 - Henrik Ekblad
23  * Contribution by a-lurker and Anticimex
24  * Contribution by Norbert Truchsess <[email protected]>
25  * Contribution by Tomas Hozza <[email protected]>
26  *
27  *
28  * DESCRIPTION
29  * The EthernetGateway sends data received from sensors to the ethernet link.
30  * The gateway also accepts input on ethernet interface, which is then sent out to the radio network.
31  *
32  * The GW code is designed for Arduino 328p / 16MHz. ATmega168 does not have enough memory to run this program.
33  *
34  * LED purposes:
35  * - To use the feature, uncomment MY_DEFAULT_xxx_LED_PIN in the sketch below
36  * - RX (green) - blink fast on radio message received. In inclusion mode will blink fast only on presentation received
37  * - TX (yellow) - blink fast on radio message transmitted. In inclusion mode will blink slowly
38  * - ERR (red) - fast blink on error during transmission error or receive crc error
39  *
40  * See http://www.mysensors.org/build/ethernet_gateway for wiring instructions.
41  *
42  */
43 
44 // Enable debug prints to serial monitor
45 #define MY_DEBUG
46 
47 // Enable and select radio type attached
48 #define MY_RADIO_RF24
49 //#define MY_RADIO_NRF5_ESB
50 //#define MY_RADIO_RFM69
51 //#define MY_RADIO_RFM95
52 
53 // Enable gateway ethernet module type
54 #define MY_GATEWAY_W5100
55 
56 // W5100 Ethernet module SPI enable (optional if using a shield/module that manages SPI_EN signal)
57 //#define MY_W5100_SPI_EN 4
58 
59 // Enable Soft SPI for NRF radio (note different radio wiring is required)
60 // The W5100 ethernet module seems to have a hard time co-operate with
61 // radio on the same spi bus.
62 #if !defined(MY_W5100_SPI_EN) && !defined(ARDUINO_ARCH_SAMD)
63 #define MY_SOFTSPI
64 #define MY_SOFT_SPI_SCK_PIN 14
65 #define MY_SOFT_SPI_MISO_PIN 16
66 #define MY_SOFT_SPI_MOSI_PIN 15
67 #endif
68 
69 // When W5100 is connected we have to move CE/CSN pins for NRF radio
70 #ifndef MY_RF24_CE_PIN
71 #define MY_RF24_CE_PIN 5
72 #endif
73 #ifndef MY_RF24_CS_PIN
74 #define MY_RF24_CS_PIN 6
75 #endif
76 
77 // Enable UDP communication
78 //#define MY_USE_UDP // If using UDP you need to set MY_CONTROLLER_IP_ADDRESS or MY_CONTROLLER_URL_ADDRESS below
79 
80 // Enable MY_IP_ADDRESS here if you want a static ip address (no DHCP)
81 #define MY_IP_ADDRESS 192,168,178,66
82 
83 // If using static ip you can define Gateway and Subnet address as well
84 //#define MY_IP_GATEWAY_ADDRESS 192,168,178,1
85 //#define MY_IP_SUBNET_ADDRESS 255,255,255,0
86 
87 // Renewal period if using DHCP
88 //#define MY_IP_RENEWAL_INTERVAL 60000
89 
90 // The port to keep open on node server mode / or port to contact in client mode
91 #define MY_PORT 5003
92 
93 // Controller ip address. Enables client mode (default is "server" mode).
94 // Also enable this if MY_USE_UDP is used and you want sensor data sent somewhere.
95 //#define MY_CONTROLLER_IP_ADDRESS 192, 168, 178, 254
96 //#define MY_CONTROLLER_URL_ADDRESS "my.controller.org"
97 
98 // The MAC address can be anything you want but should be unique on your network.
99 // Newer boards have a MAC address printed on the underside of the PCB, which you can (optionally) use.
100 // Note that most of the Arduino examples use "DEAD BEEF FEED" for the MAC address.
101 #define MY_MAC_ADDRESS 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
102 
103 
104 // Enable inclusion mode
105 #define MY_INCLUSION_MODE_FEATURE
106 // Enable Inclusion mode button on gateway
107 //#define MY_INCLUSION_BUTTON_FEATURE
108 // Set inclusion mode duration (in seconds)
109 #define MY_INCLUSION_MODE_DURATION 60
110 // Digital pin used for inclusion mode button
111 //#define MY_INCLUSION_MODE_BUTTON_PIN 3
112 
113 // Set blinking period
114 #define MY_DEFAULT_LED_BLINK_PERIOD 300
115 
116 // Flash leds on rx/tx/err
117 // Uncomment to override default HW configurations
118 //#define MY_DEFAULT_ERR_LED_PIN 7 // Error led pin
119 //#define MY_DEFAULT_RX_LED_PIN 8 // Receive led pin
120 //#define MY_DEFAULT_TX_LED_PIN 9 // Transmit led pin
121 
122 #if defined(MY_USE_UDP)
123 #include <EthernetUdp.h>
124 #endif
125 #include <Ethernet.h>
126 #include <MySensors.h>
127 
128 void setup()
129 {
130  // Setup locally attached sensors
131 }
132 
134 {
135  // Present locally attached sensors here
136 }
137 
138 void loop()
139 {
140  // Send locally attached sensors data here
141 }
142 
loop
void loop()
Main loop.
Definition: GatewayW5100.ino:138
presentation
void presentation()
Node presentation.
Definition: GatewayW5100.ino:133
setup
void setup()
Called after node initialises but before main loop.
Definition: GatewayW5100.ino:128
MySensors.h
API declaration for MySensors.