initial commit (shoulda done this earlier)
commit
0e724eb5b1
@ -0,0 +1 @@
|
||||
.pio
|
@ -0,0 +1,3 @@
|
||||
cmake_minimum_required(VERSION 3.16.0)
|
||||
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
||||
project(idf_hello_world)
|
@ -0,0 +1,27 @@
|
||||
// file: <include/lwip_hooks.h>
|
||||
#ifndef _LWIP_HOOKS_H_
|
||||
#define _LWIP_HOOKS_H_
|
||||
|
||||
#include "lwip/netif.h"
|
||||
#include "lwip/pbuf.h"
|
||||
#include "lwip/ip4.h"
|
||||
|
||||
#include "lwip/prot/udp.h"
|
||||
#include "lwip/prot/tcp.h"
|
||||
|
||||
#include "esp_log.h"
|
||||
#include "esp_err.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
int lwip_hook_ip4_input(struct pbuf *pbuf, struct netif *input_netif);
|
||||
#define LWIP_HOOK_IP4_INPUT lwip_hook_ip4_input
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _LWIP_HOOKS_H_ */
|
@ -0,0 +1,10 @@
|
||||
[env:adafruit_qtpy_esp32s2]
|
||||
platform = espressif32
|
||||
board = adafruit_qtpy_esp32s2
|
||||
framework = espidf, arduino
|
||||
build_flags =
|
||||
'-Iinclude'
|
||||
'-DESP_IDF_LWIP_HOOK_FILENAME="lwip_hooks.h"'
|
||||
lib_deps =
|
||||
adafruit/Adafruit NeoPixel
|
||||
|
@ -0,0 +1,6 @@
|
||||
# This file was automatically generated for projects
|
||||
# without default 'CMakeLists.txt' file.
|
||||
|
||||
FILE(GLOB_RECURSE app_sources ${CMAKE_SOURCE_DIR}/src/*.*)
|
||||
|
||||
idf_component_register(SRCS ${app_sources})
|
@ -0,0 +1,50 @@
|
||||
// file: <src/lwip_hooks.c>
|
||||
#include "lwip_hooks.h"
|
||||
extern void log_packet(uint16_t);
|
||||
|
||||
const char *get_protocol(u16_t type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case 1:
|
||||
return "ICMP";
|
||||
case 6:
|
||||
return "TCP";
|
||||
case 17:
|
||||
return "UDP";
|
||||
default:
|
||||
return "-";
|
||||
}
|
||||
}
|
||||
|
||||
int lwip_hook_ip4_input(struct pbuf *pbuf, struct netif *input_netif)
|
||||
{
|
||||
const struct ip_hdr *iphdr;
|
||||
const struct tcp_hdr *tcphdr;
|
||||
const struct udp_hdr *udphdr;
|
||||
char ip_address[IP_HLEN];
|
||||
u16_t protocol;
|
||||
uint16_t port;
|
||||
|
||||
iphdr = (struct ip_hdr *)pbuf->payload;
|
||||
u16_t ilen = IPH_HL(iphdr);
|
||||
protocol = (u16_t)IPH_PROTO(iphdr);
|
||||
if (protocol == 6) {
|
||||
//tcphdr = (struct tcp_hdr *)pbuf->payload;
|
||||
tcphdr = (struct tcp_hdr *)&((u32_t*)iphdr)[ilen];
|
||||
port = lwip_ntohs(tcphdr->dest);
|
||||
} else if (protocol == 17) {
|
||||
udphdr = (struct udp_hdr *)&((u32_t*)iphdr)[ilen];
|
||||
port = lwip_ntohs(udphdr->dest);
|
||||
} else {
|
||||
port = 0;
|
||||
}
|
||||
|
||||
sprintf(ip_address, "%d.%d.%d.%d", ip4_addr1_16_val(iphdr->src), ip4_addr2_16_val(iphdr->src), ip4_addr3_16_val(iphdr->src), ip4_addr4_16_val(iphdr->src));
|
||||
ESP_LOGI("HOOK", "%s: %s %u",
|
||||
get_protocol((u16_t)IPH_PROTO(iphdr)), ip_address, port);
|
||||
|
||||
log_packet(port);
|
||||
|
||||
return ESP_OK;
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
//file: main.c or main.cpp
|
||||
#include "Arduino.h"
|
||||
#include "WiFi.h"
|
||||
#include <Adafruit_Neopixel.h>
|
||||
|
||||
#define NUMPIXELS 1
|
||||
#define PIN_NEOPIXEL 39
|
||||
#define NEOPIXEL_POWER 38
|
||||
|
||||
char ssid[] = "MyWifi"; // your network SSID (name)
|
||||
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);
|
||||
|
||||
extern "C" {
|
||||
void log_packet(uint16_t port) {
|
||||
if (WiFi.status() == WL_CONNECTED) {
|
||||
pixels.rainbow(port);
|
||||
pixels.show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" void app_main()
|
||||
{
|
||||
initArduino();
|
||||
|
||||
#if defined(NEOPIXEL_POWER)
|
||||
// If this board has a power control pin, we must set it to output and high
|
||||
// in order to enable the NeoPixels. We put this in an #if defined so it can
|
||||
// be reused for other boards without compilation errors
|
||||
pinMode(NEOPIXEL_POWER, OUTPUT);
|
||||
digitalWrite(NEOPIXEL_POWER, HIGH);
|
||||
#endif
|
||||
pixels.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
|
||||
pixels.setBrightness(20); // not so bright
|
||||
|
||||
printf("Connecting");
|
||||
WiFi.begin(ssid, pass);
|
||||
while (WiFi.status() != WL_CONNECTED) {
|
||||
delay(500);
|
||||
printf(".");
|
||||
}
|
||||
printf("\nConnected!\n");
|
||||
printf("SSID: %s\n", WiFi.SSID().c_str());
|
||||
printf("IP: %s\n", WiFi.localIP().toString().c_str());
|
||||
|
||||
// Arduino-like loop()
|
||||
while(true){
|
||||
;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue