Compare commits
No commits in common. "6ac9b9a198325bed1463dd136c992dd18ff5a5cd" and "0e724eb5b14aa7032436771c9ef4c02231beab9a" have entirely different histories.
6ac9b9a198
...
0e724eb5b1
@ -7,3 +7,4 @@ build_flags =
|
|||||||
'-DESP_IDF_LWIP_HOOK_FILENAME="lwip_hooks.h"'
|
'-DESP_IDF_LWIP_HOOK_FILENAME="lwip_hooks.h"'
|
||||||
lib_deps =
|
lib_deps =
|
||||||
adafruit/Adafruit NeoPixel
|
adafruit/Adafruit NeoPixel
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
// file: <src/lwip_hooks.c>
|
// file: <src/lwip_hooks.c>
|
||||||
#include "lwip_hooks.h"
|
#include "lwip_hooks.h"
|
||||||
extern void log_packet(uint16_t, u16_t);
|
extern void log_packet(uint16_t);
|
||||||
|
|
||||||
const char *get_protocol(u16_t type)
|
const char *get_protocol(u16_t type)
|
||||||
{
|
{
|
||||||
@ -44,7 +44,7 @@ int lwip_hook_ip4_input(struct pbuf *pbuf, struct netif *input_netif)
|
|||||||
ESP_LOGI("HOOK", "%s: %s %u",
|
ESP_LOGI("HOOK", "%s: %s %u",
|
||||||
get_protocol((u16_t)IPH_PROTO(iphdr)), ip_address, port);
|
get_protocol((u16_t)IPH_PROTO(iphdr)), ip_address, port);
|
||||||
|
|
||||||
log_packet(port, (u16_t)IPH_PROTO(iphdr));
|
log_packet(port);
|
||||||
|
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
|
120
src/main.cpp
120
src/main.cpp
@ -3,103 +3,20 @@
|
|||||||
#include "WiFi.h"
|
#include "WiFi.h"
|
||||||
#include <Adafruit_Neopixel.h>
|
#include <Adafruit_Neopixel.h>
|
||||||
|
|
||||||
#define NUMPIXELS 8
|
#define NUMPIXELS 1
|
||||||
#define PIN_NEOPIXEL_ONBOARD 39
|
#define PIN_NEOPIXEL 39
|
||||||
#define PIN_NEOPIXEL 9
|
|
||||||
#define NEOPIXEL_POWER 38
|
#define NEOPIXEL_POWER 38
|
||||||
|
|
||||||
#define PROTO_ICMP 1
|
char ssid[] = "MyWifi"; // your network SSID (name)
|
||||||
#define PROTO_TCP 6
|
|
||||||
#define PROTO_UDP 17
|
|
||||||
|
|
||||||
enum mode{Disco, Gauge};
|
|
||||||
enum mode active_mode = Disco;
|
|
||||||
|
|
||||||
char ssid[] = "MySSID"; // your network SSID (name)
|
|
||||||
char pass[] = "MyPassphrase"; // your network password (use for WPA, or use as key for WEP)
|
char pass[] = "MyPassphrase"; // your network password (use for WPA, or use as key for WEP)
|
||||||
|
|
||||||
Adafruit_NeoPixel pixels(NUMPIXELS, PIN_NEOPIXEL, NEO_GRB + NEO_KHZ800);
|
Adafruit_NeoPixel pixels(NUMPIXELS, PIN_NEOPIXEL, NEO_GRB + NEO_KHZ800);
|
||||||
Adafruit_NeoPixel onboard_pixel(1, PIN_NEOPIXEL_ONBOARD, NEO_GRB + NEO_KHZ800);
|
|
||||||
|
|
||||||
long last_gauge_show = 0;
|
|
||||||
int packets_received = 0;
|
|
||||||
uint32_t gauge_colors[] = {
|
|
||||||
pixels.Color(0, 255, 0), // red
|
|
||||||
pixels.Color(128, 255, 0),
|
|
||||||
pixels.Color(191, 255, 0),
|
|
||||||
pixels.Color(255, 255, 0), // yellow
|
|
||||||
pixels.Color(255, 191, 0),
|
|
||||||
pixels.Color(255, 128, 0),
|
|
||||||
pixels.Color(255, 64, 0),
|
|
||||||
pixels.Color(255, 0, 0) // red
|
|
||||||
};
|
|
||||||
|
|
||||||
void ssh_attempt() {
|
|
||||||
printf("Someone connected to SSH!");
|
|
||||||
pixels.fill(pixels.Color(255, 0, 0));
|
|
||||||
pixels.show();
|
|
||||||
delay(200);
|
|
||||||
pixels.clear();
|
|
||||||
pixels.show();
|
|
||||||
delay(100);
|
|
||||||
pixels.fill(pixels.Color(255, 0, 0));
|
|
||||||
pixels.show();
|
|
||||||
delay(200);
|
|
||||||
pixels.fill(pixels.Color(0,0,0));
|
|
||||||
pixels.show();
|
|
||||||
}
|
|
||||||
|
|
||||||
void icmp_ping() {
|
|
||||||
pixels.setPixelColor(3, pixels.Color(255, 255, 255));
|
|
||||||
pixels.setPixelColor(7, pixels.Color(255, 255, 255));
|
|
||||||
pixels.show();
|
|
||||||
delay(100);
|
|
||||||
pixels.setPixelColor(3, 0);
|
|
||||||
pixels.setPixelColor(7, 0);
|
|
||||||
pixels.show();
|
|
||||||
}
|
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
void log_packet(uint16_t port, u16_t proto) {
|
void log_packet(uint16_t port) {
|
||||||
if (WiFi.status() == WL_CONNECTED) {
|
if (WiFi.status() == WL_CONNECTED) {
|
||||||
if (active_mode == Disco) {
|
pixels.rainbow(port);
|
||||||
uint32_t color = pixels.ColorHSV(port);
|
pixels.show();
|
||||||
switch (proto) {
|
|
||||||
case PROTO_ICMP:
|
|
||||||
icmp_ping();
|
|
||||||
break;
|
|
||||||
case PROTO_TCP:
|
|
||||||
if (port == 22) {
|
|
||||||
ssh_attempt();
|
|
||||||
} else {
|
|
||||||
pixels.setPixelColor(0, color);
|
|
||||||
pixels.setPixelColor(1, color);
|
|
||||||
pixels.setPixelColor(2, color);
|
|
||||||
pixels.show();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case PROTO_UDP:
|
|
||||||
pixels.setPixelColor(4, color);
|
|
||||||
pixels.setPixelColor(5, color);
|
|
||||||
pixels.setPixelColor(6, color);
|
|
||||||
pixels.show();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} else if (active_mode == Gauge) {
|
|
||||||
packets_received++;
|
|
||||||
if (millis() - last_gauge_show > 200) {
|
|
||||||
int num_leds = round(log((double)packets_received));
|
|
||||||
printf("gauge: Packets: %d LEDs: %d", packets_received, num_leds);
|
|
||||||
if (num_leds > NUMPIXELS) {num_leds = NUMPIXELS;}
|
|
||||||
pixels.clear();
|
|
||||||
for(int i = 0; i < num_leds; i++) {
|
|
||||||
pixels.setPixelColor(i, gauge_colors[i]);
|
|
||||||
}
|
|
||||||
pixels.show();
|
|
||||||
packets_received = 0;
|
|
||||||
last_gauge_show = millis();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -116,41 +33,20 @@ extern "C" void app_main()
|
|||||||
digitalWrite(NEOPIXEL_POWER, HIGH);
|
digitalWrite(NEOPIXEL_POWER, HIGH);
|
||||||
#endif
|
#endif
|
||||||
pixels.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
|
pixels.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
|
||||||
onboard_pixel.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
|
|
||||||
pixels.setBrightness(20); // not so bright
|
pixels.setBrightness(20); // not so bright
|
||||||
onboard_pixel.setBrightness(20);
|
|
||||||
|
|
||||||
printf("Connecting");
|
printf("Connecting");
|
||||||
onboard_pixel.fill(onboard_pixel.Color(255, 255, 0));
|
|
||||||
onboard_pixel.show();
|
|
||||||
WiFi.begin(ssid, pass);
|
WiFi.begin(ssid, pass);
|
||||||
while (WiFi.status() != WL_CONNECTED) {
|
while (WiFi.status() != WL_CONNECTED) {
|
||||||
delay(500);
|
delay(500);
|
||||||
printf(".");
|
printf(".");
|
||||||
}
|
}
|
||||||
onboard_pixel.fill(onboard_pixel.Color(0, 255, 0));
|
|
||||||
onboard_pixel.show();
|
|
||||||
|
|
||||||
printf("\nConnected!\n");
|
printf("\nConnected!\n");
|
||||||
printf("SSID: %s\n", WiFi.SSID().c_str());
|
printf("SSID: %s\n", WiFi.SSID().c_str());
|
||||||
printf("IP: %s\n", WiFi.localIP().toString().c_str());
|
printf("IP: %s\n", WiFi.localIP().toString().c_str());
|
||||||
|
|
||||||
long last_touch = 0;
|
|
||||||
|
|
||||||
// Arduino-like loop()
|
// Arduino-like loop()
|
||||||
while(true){
|
while(true){
|
||||||
int capacity = touchRead(8);
|
;
|
||||||
if (capacity > 20000) {
|
|
||||||
long cur_time = millis();
|
|
||||||
if (cur_time - last_touch > 500) {
|
|
||||||
active_mode = mode((active_mode + 1) % (Gauge + 1));
|
|
||||||
pixels.clear();
|
|
||||||
printf("changed mode: %u!\n", active_mode);
|
|
||||||
if (active_mode == Gauge) {
|
|
||||||
last_gauge_show = millis();
|
|
||||||
}
|
|
||||||
last_touch = cur_time;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user