MySensors Library & Examples  2.3.2-38-gaa76d26
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-2020 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 //#define MY_PJON
53 
54 // Enable gateway ethernet module type
55 #define MY_GATEWAY_W5100
56 
57 // W5100 Ethernet module SPI enable (optional if using a shield/module that manages SPI_EN signal)
58 //#define MY_W5100_SPI_EN 4
59 
60 // Enable Soft SPI for NRF radio (note different radio wiring is required)
61 // The W5100 ethernet module seems to have a hard time co-operate with
62 // radio on the same spi bus.
63 #if !defined(MY_W5100_SPI_EN) && !defined(ARDUINO_ARCH_SAMD)
64 #define MY_SOFTSPI
65 #define MY_SOFT_SPI_SCK_PIN 14
66 #define MY_SOFT_SPI_MISO_PIN 16
67 #define MY_SOFT_SPI_MOSI_PIN 15
68 #endif
69 
70 // When W5100 is connected we have to move CE/CSN pins for NRF radio
71 #ifndef MY_RF24_CE_PIN
72 #define MY_RF24_CE_PIN 5
73 #endif
74 #ifndef MY_RF24_CS_PIN
75 #define MY_RF24_CS_PIN 6
76 #endif
77 
78 // Enable UDP communication
79 //#define MY_USE_UDP // If using UDP you need to set MY_CONTROLLER_IP_ADDRESS or MY_CONTROLLER_URL_ADDRESS below
80 
81 // Enable MY_IP_ADDRESS here if you want a static ip address (no DHCP)
82 #define MY_IP_ADDRESS 192,168,178,66
83 
84 // If using static ip you can define Gateway and Subnet address as well
85 //#define MY_IP_GATEWAY_ADDRESS 192,168,178,1
86 //#define MY_IP_SUBNET_ADDRESS 255,255,255,0
87 
88 // The port to keep open on node server mode / or port to contact in client mode
89 #define MY_PORT 5003
90 
91 // Controller ip address. Enables client mode (default is "server" mode).
92 // Also enable this if MY_USE_UDP is used and you want sensor data sent somewhere.
93 //#define MY_CONTROLLER_IP_ADDRESS 192, 168, 178, 254
94 //#define MY_CONTROLLER_URL_ADDRESS "my.controller.org"
95 
96 // The MAC address can be anything you want but MUST be unique on your network.
97 // Newer boards have a MAC address printed on the underside of the PCB, which you can (optionally) use.
98 // Note that most of the Arduino examples use "DEAD BEEF FEED" for the MAC address
99 // so make sure you don't have multiple Arduinos using the same MAC address.
100 #define MY_MAC_ADDRESS 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
101 
102 
103 // Enable inclusion mode
104 #define MY_INCLUSION_MODE_FEATURE
105 // Enable Inclusion mode button on gateway
106 //#define MY_INCLUSION_BUTTON_FEATURE
107 // Set inclusion mode duration (in seconds)
108 #define MY_INCLUSION_MODE_DURATION 60
109 // Digital pin used for inclusion mode button
110 //#define MY_INCLUSION_MODE_BUTTON_PIN 3
111 
112 // Set blinking period
113 #define MY_DEFAULT_LED_BLINK_PERIOD 300
114 
115 // Flash leds on rx/tx/err
116 // Uncomment to override default HW configurations
117 //#define MY_DEFAULT_ERR_LED_PIN 7 // Error led pin
118 //#define MY_DEFAULT_RX_LED_PIN 8 // Receive led pin
119 //#define MY_DEFAULT_TX_LED_PIN 9 // Transmit led pin
120 
121 #if defined(MY_USE_UDP)
122 #include <EthernetUdp.h>
123 #endif
124 #include <Ethernet.h>
125 #include <MySensors.h>
126 
127 void setup()
128 {
129  // Setup locally attached sensors
130 }
131 
133 {
134  // Present locally attached sensors here
135 }
136 
137 void loop()
138 {
139  // Send locally attached sensors data here
140 }
141 
loop
void loop()
Main loop.
Definition: GatewayW5100.ino:137
presentation
void presentation()
Node presentation.
Definition: GatewayW5100.ino:132
setup
void setup()
Called after node initialises but before main loop.
Definition: GatewayW5100.ino:127
MySensors.h
API declaration for MySensors.