#include <SPI.h>
#include <RF24.h>
#include <RF24Network.h>
#include "HTML.h"
#include "RF24Mesh.h"
RF24 radio(7, 8);
RF24Network network(radio);
RF24Mesh mesh(radio, network);
#if defined(ARDUINO_ARCH_ESP8266)
#define LED_PIN BUILTIN_LED
#else
#define LED_PIN A3
#endif
static unsigned short generate_tcp_stats();
void setup() {
Serial.begin(115200);
Serial.println("start");
pinMode(LED_PIN, OUTPUT);
IPAddress myIP(10, 10, 2, 4);
mesh.begin();
IPAddress gwIP(10, 10, 2, 2);
server.begin();
server.setTimeout(30000);
}
uint32_t mesh_timer = 0;
void loop() {
if (millis() - mesh_timer > 30000) {
mesh_timer = millis();
if (!mesh.checkConnection()) {
if (mesh.renewAddress() == MESH_DEFAULT_ADDRESS) {
mesh.begin();
}
}
}
size_t size;
uint8_t pageReq = 0;
generate_tcp_stats();
while ((size = client.available()) > 0) {
if (size >= 7) {
char slash[] = { "/" };
client.setTimeout(10000);
client.findUntil(slash, slash);
char buf[3] = { " " };
if (client.available() >= 2) {
buf[0] = client.read();
buf[1] = client.read();
if (strcmp(buf, "ON") == 0) {
pageReq = 1;
} else if (strcmp(buf, "OF") == 0) {
pageReq = 1;
} else if (strcmp(buf, "ST") == 0) {
pageReq = 2;
} else if (strcmp(buf, "CR") == 0) {
pageReq = 3;
} else if (buf[0] == ' ') {
pageReq = 4;
}
}
}
client.flush();
}
switch (pageReq) {
case 2:
break;
case 3:
break;
case 4:
break;
case 1:
break;
default:
break;
}
client.stop();
Serial.println(F("********"));
}
}
static unsigned short generate_tcp_stats() {
struct uip_conn* conn;
conn = &uip_conns[i];
if (conn->appstate) {
Serial.print(F("Connection no "));
Serial.println(i);
Serial.print(F("Local Port "));
Serial.println(htons(conn->lport));
Serial.print(F("Remote IP/Port "));
Serial.print(htons(conn->ripaddr[0]) >> 8);
Serial.print(F("."));
Serial.print(htons(conn->ripaddr[0]) & 0xff);
Serial.print(F("."));
Serial.print(htons(conn->ripaddr[1]) >> 8);
Serial.print(F("."));
Serial.print(htons(conn->ripaddr[1]) & 0xff);
Serial.print(F(":"));
Serial.println(htons(conn->rport));
Serial.print(F("Outstanding "));
Serial.println((uip_outstanding(conn)) ? '*' : ' ');
}
}
return 1;
}
void main_page(EthernetClient &_client)
void stats_page(EthernetClient &_client)
void credits_page(EthernetClient &_client)
RF24EthernetClass RF24Ethernet
#define UIP_CONF_MAX_CONNECTIONS
Maximum number of TCP connections.