RF24Ethernet - TCP/IP over RF24Network v1.6.12
TMRh20 - Pushing the practical limits of RF24 modules
Loading...
Searching...
No Matches
RF24Ethernet.h
Go to the documentation of this file.
1/*
2 RF24Ethernet by TMRh20 2014-2015
3
4 https://github.com/TMRh20
5
6 RF24Ethernet.h - Arduino implementation of a uIP wrapper class.
7 Copyright (c) 2014 tmrh20@gmail.com, github.com/TMRh20
8 Copyright (c) 2013 Norbert Truchsess <norbert.truchsess@t-online.de>
9 All rights reserved.
10 This program is free software: you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation, either version 3 of the License, or
13 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#ifndef RF24Ethernet_h
23 #define RF24Ethernet_h
24
25/**
26 * @file RF24Ethernet.h
27 *
28 * Class declaration for RF24Ethernet
29 */
30
31 #include <Arduino.h>
32
33extern "C" {
34 #include "uip-conf.h"
35 #include "utility/uip.h"
36 #include "utility/uiptimer.h"
37 #include "utility/uip_arp.h"
38}
39
40 #include "RF24Ethernet_config.h"
41 #include <RF24.h>
42 #include <RF24Network.h>
43 #if !defined(RF24_TAP) // Using RF24Mesh
44 #include <RF24Mesh.h>
45 #endif
46
47 #include "ethernet_comp.h"
48 #include "IPAddress.h"
49 #include "RF24Client.h"
50 #include "RF24Server.h"
51
52 #if UIP_CONF_UDP > 0
53 #include "RF24Udp.h"
54 #include "Dns.h"
55 #endif
56
57 #define UIPETHERNET_FREEPACKET 1
58 #define UIPETHERNET_SENDPACKET 2
59
60 //#define TUN // Use only the tcp protocol, no ethernet headers or arps
61 #define TAP // Include ethernet headers
62
63 #if defined(TAP)
64 #define BUF ((struct uip_eth_hdr*)&uip_buf[0])
65 #endif
66//#define BUF ((struct uip_tcpip_hdr *)&uip_buf[UIP_LLH_LEN])
67
68 #define uip_seteth_addr(eaddr) \
69 do { \
70 uip_ethaddr.addr[0] = eaddr[0]; \
71 uip_ethaddr.addr[1] = eaddr[1]; \
72 uip_ethaddr.addr[2] = eaddr[2]; \
73 uip_ethaddr.addr[3] = eaddr[3]; \
74 uip_ethaddr.addr[4] = eaddr[4]; \
75 uip_ethaddr.addr[5] = eaddr[5]; \
76 } while (0)
77 #define uip_ip_addr(addr, ip) memcpy(addr, &ip[0], 4)
78
79 #define ip_addr_uip(a) IPAddress(a[0] & 0xFF, a[0] >> 8, a[1] & 0xFF, a[1] >> 8) //TODO this is not IPV6 capable
80
81 #define uip_seteth_addr(eaddr) \
82 do { \
83 uip_ethaddr.addr[0] = eaddr[0]; \
84 uip_ethaddr.addr[1] = eaddr[1]; \
85 uip_ethaddr.addr[2] = eaddr[2]; \
86 uip_ethaddr.addr[3] = eaddr[3]; \
87 uip_ethaddr.addr[4] = eaddr[4]; \
88 uip_ethaddr.addr[5] = eaddr[5]; \
89 } while (0)
90
91/**
92 * @warning <b>This is used internally. Use IPAddress instead. </b>
93 */
94typedef struct
95{
96 int a, b, c, d;
97} IP_ADDR;
98
99class RF24;
100class RF24Network;
101
103{ //: public Print {
104public:
105 /**
106 * Constructor to set up the Ethernet layer. Requires the radio and network to be configured by the user
107 * this allows users to set custom settings at the radio or network level
108 */
109 #if !defined(RF24_TAP) // Using RF24Mesh
110 RF24EthernetClass(RF24& _radio, RF24Network& _network, RF24Mesh& _mesh);
111 #else
112 RF24EthernetClass(RF24& _radio, RF24Network& _network);
113 #endif
114
115 /** Basic constructor */
117
118 /**
119 * @note Deprecated, maintained for backwards compatibility with old examples
120 *
121 * This function is no longer needed, and does nothing
122 */
123 void use_device();
124
125 /**
126 * Configure the IP address and subnet mask of the node. This is independent of the RF24Network layer, so the IP
127 * and subnet only have to conform to standard IP routing rules within your network
128 */
129 void begin(IP_ADDR myIP, IP_ADDR subnet);
130
131 /**
132 * Configure the IP address and subnet mask of the node. This is independent of the RF24Network layer, so the IP
133 * and subnet only have to conform to standard IP routing rules within your network
134 */
135 void begin(IPAddress ip);
136 void begin(IPAddress ip, IPAddress dns);
137 void begin(IPAddress ip, IPAddress dns, IPAddress gateway);
138 void begin(IPAddress ip, IPAddress dns, IPAddress gateway, IPAddress subnet);
139
140 /**
141 * Configure the gateway IP address. This is generally going to be your master node with RF24Network address 00.
142 */
143 void set_gateway(IPAddress gwIP);
144
145 /**
146 * Listen to a specified port - This will likely be changed to closer match the Arduino Ethernet API with server.begin();
147 */
148 void listen(uint16_t port);
149
150 /**
151 * Sets the MAC address of the RF24 module, which is an RF24Network address
152 * Specify an Octal address to assign to this node, which will be used as the Ethernet mac address
153 * If setting up only a few nodes, use 01 to 05
154 * Please reference the RF24Network documentation for information on setting up a static network
155 * RF24Mesh will be integrated to provide this automatically
156 */
157 void setMac(uint16_t address);
158
159 /** Sets the Radio channel/frequency to use (0-127) */
160 void setChannel(uint8_t channel);
161
162 /** Indicates whether data is available. */
164
165 /** Returns the local IP address */
166 IPAddress localIP();
167
168 /** Returns the subnet mask */
169 IPAddress subnetMask();
170
171 /** Returns the gateway IP address */
172 IPAddress gatewayIP();
173
174 /** Returns the DNS server IP address */
175 IPAddress dnsServerIP();
176
177 /** Keeps the TCP/IP stack running & processing incoming data */
178 void update();
179 //uint8_t *key;
180
181private:
182 RF24& radio;
183 RF24Network& network;
184 #if !defined(RF24_TAP) // Using RF24Mesh
185 RF24Mesh& mesh;
186 #endif
187
188 static IPAddress _dnsServerAddress;
189 void configure(IPAddress ip, IPAddress dns, IPAddress gateway, IPAddress subnet);
190 // tick() must be called at regular intervals to process the incoming serial
191 // data and issue IP events to the sketch. It does not return until all IP
192 // events have been processed.
193 static void tick();
194 static void network_send();
195
196 uint8_t RF24_Channel;
197
198 struct timer periodic_timer;
199 #if defined RF24_TAP
200 struct timer arp_timer;
201 #endif
202 friend class RF24Server;
203 friend class RF24Client;
204 friend class RF24UDP;
205};
206
208
209#endif // RF24Ethernet_h
210
211/**
212 * @example Getting_Started_SimpleServer_Mesh.ino
213 * <b>Updated: TMRh20 2014 </b><br>
214 *
215 * This is an example of how to use the RF24Ethernet class to create a web server which will allow you to connect via
216 * any device with a web-browser. The url is http://your_chosen_IP:1000
217 */
218
219/**
220 * @example Getting_Started_SimpleClient_Mesh.ino
221 *
222 * This is an example of how to use the RF24Ethernet class to connect out to a web server and retrieve data via HTTP.
223 */
224
225/**
226 * @example Getting_Started_SimpleClient_Mesh_DNS.ino
227 *
228 * This is an example of how to use the RF24Ethernet class to connect out to a web server and retrieve data via HTTP,
229 * using DNS lookups instead of IP address.
230 */
231
232/**
233 * @example SimpleClient_Mesh.ino
234 *
235 * This is an example of how to use the RF24Ethernet class to connect out to a web server and retrieve data via HTTP.
236 * It also demonstrates how to read from the HTTP header to read the Content-Length before reading the data.
237 */
238
239/**
240 * @example InteractiveServer_Mesh.ino
241 *
242 * This is an example of how to create a more advanced interactive web server.<br>
243 * This example uses [HTML.h](InteractiveServer__Mesh_2HTML_8h.html) from the
244 * example's directory.
245 */
246
247/**
248 * @example mqtt_basic.ino
249 *
250 * This is the example taken from the PubSub library (https://github.com/knolleary/pubsubclient) & slightly modified to include RF24Ethernet/RF24Mesh.
251 */
252
253/**
254 * @example mqtt_basic_2.ino
255 *
256 * A copy of the initial MQTT example using MQTT library https://github.com/256dpi/arduino-mqtt/ slightly modified to include RF24Ethernet/RF24Mesh.
257 */
258
259/**
260 * @example SLIP_Gateway.ino
261 *
262 * This example demonstrates how to use an Arduino as a gateway to a SLIP enabled device.
263 */
264
265/**
266 * @example SLIP_InteractiveServer.ino
267 *
268 * This example demonstrates how to use RF24Mesh with RF24Ethernet when working with a SLIP or TUN interface.
269 * <br>This example uses [HTML.h](SLIP__InteractiveServer_2HTML_8h.html) from the
270 * example's directory.
271 */
RF24EthernetClass RF24Ethernet
friend class RF24UDP
Definition: RF24Ethernet.h:204
void setMac(uint16_t address)
void setChannel(uint8_t channel)
IPAddress dnsServerIP()
void listen(uint16_t port)
IPAddress localIP()
IPAddress subnetMask()
void set_gateway(IPAddress gwIP)
void begin(IP_ADDR myIP, IP_ADDR subnet)
IPAddress gatewayIP()