This is an example of how to use the RF24Ethernet class to connect out to a web server and retrieve data via HTTP, using DNS lookups instead of IP address.
#include <RF24.h>
#include <RF24Network.h>
#include <RF24Mesh.h>
RF24 radio(7, 8);
RF24Network network(radio);
RF24Mesh mesh(radio, network);
char icewind[] = { "109.120.203.163" };
char ascii[] = { "artscene.textfiles.com" };
char* host = ascii;
void setup() {
Serial.begin(115200);
Serial.println(F("Start"));
IPAddress myIP(10, 10, 2, 4);
IPAddress myDNS(8, 8, 8, 8);
mesh.begin();
IPAddress gwIP(10, 10, 2, 2);
}
uint32_t counter = 0;
uint32_t reqTimer = 0;
uint32_t mesh_timer = 0;
void loop() {
if (Serial.available()) {
char c = Serial.read();
if (c == 'p') {
host = ascii;
} else if (c == 'g') {
host = icewind;
}
}
if (millis() - mesh_timer > 12000) {
mesh_timer = millis();
if (!mesh.checkConnection()) {
if (mesh.renewAddress() == MESH_DEFAULT_ADDRESS) {
mesh.begin();
}
}
}
size_t size;
if ((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 /asciiart/texthistory.txt HTTP/1.1");
client.println("Host: artscene.textfiles.com");
} else {
client.println("GET /web/blyad.club/library/litrature/Salvatore,%20R.A/Salvatore,%20R.A%20-%20Icewind%20Dale%20Trilogy%201%20-%20Crystal%20Shard,%20The.txt HTTP/1.1");
client.println("Host: 109.120.203.163");
}
client.println("Connection: close");
client.println();
} else {
Serial.println(F("connection failed"));
}
}
RF24EthernetClass RF24Ethernet