/* * RF24Ethernet Serial Gateway Example using SLIP * * This example will allow RF24Ethernet to be used with any device capable of utilizing the SLIP protocol * * * When using SLIP, there are 3 main differences: * 1. The RF24Mesh layer must be used to provide MAC/IP translation * 2. For child nodes (NOT this master/gateway node) The specified RF24Mesh nodeID must be the same as the last octet of the IP * ie: IP: 192.168.1.2 NodeId must be 2 * * 3. The RF24Ethernet library must be configured for TUN * a: Open the uip_conf.h file, set the #define UIP_CONF_LLH_LEN 0 * * The following commands must be run on the Linux device to enable slip * 1. On RPi, cd /dev * 2. Type 'ls' , note the ttyUSB devices * 3. Connect your Arduino * 4. Type 'ls' and look for a new device ttyUSB where is a number * 5. Run sudo modprobe slip * 6. Run sudo slattach -L -s 115200 -p slip /dev/ttyUSB & * 7. Note the & at the end of the previous command. Without it, slattach will appear to hang and CTRL+C will exit. * 7. Run ifconfig , note the sl device * 8. Run sudo ifconfig sl 10.10.3.1 * 9. Run sudo route add -net 10.10.3.0/24 gw 10.10.3.1 * 10. The gateway is now up and running. Active RF24Ethernet nodes should be pingable. Note: If using an ip of 192.168.3.1 for the gateway, the commands are very similar: ie: sudo route add -net 192.168.3.0/24 gw 192.168.3.1 * RF24Ethernet uses the uIP stack by Adam Dunkels * * This example demonstrates how to configure a sensor node to act as a webserver and * allows a user to control a connected LED by clicking links on the webpage * The requested URL is used as input, to determine whether to turn the LED off or on */ #include #include #include #include #include #include RF24 radio(7, 8); RF24Network network(radio); RF24Mesh mesh(radio, network); RF24EthernetClass RF24Ethernet(radio, network, mesh); #define MY_MESHID 11 #define LED_TXRX // Flash LED on SLIP device TX or RX #define SLIP_DEBUG // Will delay and flash LEDs if unable to find a node by IP address ( node needs to reconnect via RF24Mesh ) // Define the LED pin for the above two options #define DEBUG_LED_PIN A3 // NOTE: IMPORTANT this should be set to the same value as the UIP_BUFSIZE and // the MAX_PAYLOAD_SIZE in RF24Network. The default is 120 bytes #define UIP_BUFFER_SIZE MAX_PAYLOAD_SIZE uint8_t slip_buf[UIP_BUFFER_SIZE]; // MSS + TCP Header Length //Function to send incoming network data to the SLIP interface void networkToSLIP(); void setup() { // Set up the speed of our serial link. Serial.begin(115200); printf_begin(); Serial.println("start"); // This step is very important. When using TUN or SLIP, the IP of the device // must be configured as the NodeID in the RF24Mesh layer mesh.setNodeID(MY_MESHID); mesh.begin(); // Set the IP address we'll be using. Make sure this doesn't conflict with // any IP addresses or subnets on your LAN or you won't be able to connect to // either the Arduino or your LAN... // NOTE: The last octet/last digit of the IP must match the RF24Mesh nodeID above IPAddress myIP(10, 10, 2, MY_MESHID); Ethernet.begin(myIP); // If you'll be making outgoing connections from the Arduino to the rest of // the world, you'll need a gateway set up. IPAddress gwIP(10, 10, 2, 1); Ethernet.set_gateway(gwIP); //Optional radio.printDetails(); // Use the serial port as the SLIP device slipdev_init(Serial); // LED stuff pinMode(DEBUG_LED_PIN, OUTPUT); #if defined(SLIP_DEBUG) digitalWrite(DEBUG_LED_PIN, HIGH); delay(200); digitalWrite(DEBUG_LED_PIN, LOW); #endif } uint32_t active_timer = 0; void loop() { /* // Provide RF24Network addresses to connecting & reconnecting nodes if (millis() > 10000) { mesh.DHCP(); }*/ //Ensure any incoming user payloads are read from the buffer while (network.available()) { RF24NetworkHeader header; network.read(header, 0, 0); } // Handle external (TCP) data // Note: If not utilizing RF24Network payloads directly, users can edit the RF24Network_config.h file // and uncomment #define DISABLE_USER_PAYLOADS. This can save a few hundred bytes of RAM. if (mesh.update() == EXTERNAL_DATA_TYPE) { networkToSLIP(); } // Poll the SLIP device for incoming data //uint16_t len = slipdev_poll(); uint16_t len; if ((len = slipdev_poll()) > 0) { if (len > MAX_PAYLOAD_SIZE) { return; } RF24NetworkHeader header(01, EXTERNAL_DATA_TYPE); header.to_node = 0; network.write(header, &slip_buf, len); } } void networkToSLIP() { RF24NetworkFrame* frame = network.frag_ptr; size_t size = frame->message_size; uint8_t* pointer = frame->message_buffer; slipdev_send(pointer, size); //digitalWrite(DEBUG_LED_PIN, !digitalRead(DEBUG_LED_PIN)); } void flashLED() { #if defined(SLIP_DEBUG) digitalWrite(DEBUG_LED_PIN, HIGH); delay(200); digitalWrite(DEBUG_LED_PIN, LOW); delay(200); digitalWrite(DEBUG_LED_PIN, HIGH); delay(200); digitalWrite(DEBUG_LED_PIN, LOW); delay(200); digitalWrite(DEBUG_LED_PIN, HIGH); delay(200); digitalWrite(DEBUG_LED_PIN, LOW); delay(200); #endif }