This example demonstrates "headless" use of a client, without a gateway device like Raspberry Pi/Linux
#define USE_NRF24
#ifdef USE_NRF24
#include <RF24.h>
#include <RF24Network.h>
#include "RF24Mesh.h"
RF24 radio(7, 8);
RF24Network network(radio);
RF24Mesh mesh(radio, network);
#else
#include <nrf_to_nrf.h>
#include <RF24Network.h>
#include "RF24Mesh.h"
nrf_to_nrf radio;
RF52Network network(radio);
RF52Mesh mesh(radio, network);
#endif
IPAddress ascii(10, 1, 3, 1);
IPAddress host(ascii);
void connect();
void setup() {
Serial.begin(115200);
while (!Serial) {}
Serial.println(F("Start"));
IPAddress myIP(10, 1, 3, 2);
IPAddress gwIP(10, 1, 3, 1);
mesh.begin(65);
}
uint32_t counter = 0;
uint32_t reqTimer = 0;
uint32_t mesh_timer = 0;
void loop() {
if (millis() - mesh_timer > 12000) {
mesh_timer = millis();
if (!mesh.checkConnection()) {
Serial.println("Renew");
if (mesh.renewAddress() == MESH_DEFAULT_ADDRESS) {
mesh.begin(65);
}
}
}
size_t size;
while ((size = client.available()) > 0) {
char c = client.read();
Serial.print(c);
counter++;
}
if (!client.connected()) {
Serial.println();
Serial.println(F("Disconnect. Waiting for disconnect timeout"));
client.stop();
reqTimer = millis();
while (millis() - reqTimer < 5000 && !client.available()) {
}
connect();
}
}
void connect() {
Serial.println(F("connecting"));
if (client.connect(host, 80)) {
Serial.println(F("connected"));
if (host == ascii) {
client.println("GET / HTTP/1.1");
client.println("Host: 10.1.3.1");
}
client.println("Connection: close");
client.println();
} else {
Serial.println(F("connection failed"));
mesh.renewAddress();
}
}
RF24EthernetClass RF52EthernetClass
RF24EthernetClass RF24Ethernet