-
Notifications
You must be signed in to change notification settings - Fork 0
Home
I decided to try to develop an IOT traffic statistics for my internet connection becouse I didn't find anything similar to what I needed. I'm not a developer, I worked for a little period 20 years ago on on old technology, therefore I want to highlight that for sure it is not the best in class about development style and maybe it is not reliable and I don't guarantee nothing about it. Nevertheless I'm using at home and it seems that it can run with no problem for months. I'm releasing, although it is not a good example of development. Please note I would like to thanks all guys developing on arduino and releasing their exceptional work for free, obviously first who developed the libraries used in my work. The sketch has to be compiled with Arduino IDE and uses the following libraries:
Influx DB client for Arduino by Tobias Schuerg
I would also like to thank ofekp maker of TinyUPnp that helped me a lot to understand how to collect the traffic information on my router using IGD UPNP.
Please note that almost for sure you will have to deep dive the UPNP replies of your router in order to use it. I tried to parametrized all tokens in order to simplify porting to other routers by I do not guarantee it will be simple.
After having installed all libraries reported above in Arduino IDE, it will be needed to modify in preferences.h all variables you need to adapt to your UPNP replies coming from the router or Internet Gateway.
PLEASE REMEMBER TO USE correct "User_Setup_routerstats32.h" copying it in TFT espi folder library and renaming it ""User_Setup.h"
MQTT configuration
It is possible to have one IOTroutertraffic querying the router and publish data to MQTT queue (I have it on a raspberry in my LAN) and many others IOTroutertraffic subscribing the queue to visualize data. In this way you don't overload the router with additional requests if you, as me, need two or three IOTroutertraffic placed in different rooms at home.
`#define debug_serial //comment out if not debugging
#define name_sensor_default "ROUTERSTATS" // NOME HOST
#define MQTT_Y //use MQTT (publisher or subscriber)
#define publisher // publisher or subscriber of MQTT`
Internet Gateway / router address and upnp call path
My UPNP API are available calling the two pages below:
opening it on a browser allowed me to identify the post calls and then, via postman, I built the routines to collect traffic data from pages.
`String _ip = "http://192.168.0.1";
String _port = "49152";
String _path = "/upnp/control/WANCommonIFC1";
#define ping_site "8.8.8.8"
#define max_readings 300 //5 minutes entry for hystorical data
int freq_request = 990; //UPNP request every 1000 msec approx
// line max bdwth
int max_download_rate = 7000;
int max_upload_rate = 800;
unsigned long max_speed_r, max_speed_s = 0;`
Tokens to isolate traffic data from UPNP pages of my router
`//---------- UPNP IDG configuration
//actions&services available on my router
String gettotalbytesreceived = "GetTotalBytesReceived";
String bytesreceivedresult = "NewTotalBytesReceived";
String gettotalbytessent = "GetTotalBytesSent";
String bytessentresult = "NewTotalBytesSent";
String gettotalpacketssent = "GetTotalPacketsSent";
String packetsentresult = "NewTotalPacketsSent";
String gettotalpacketsreceived = "GetTotalPacketsReceived";
String packetreceivedresult = "NewTotalPacketsReceived";
String getcommonlinkproperties = "GetCommonLinkProperties";
String linkpropertiesresult = "NewPhysicalLinkStatus";
String _service = ""urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1"";`
Final result with 3d printed box (design available) and Grafana dashboard (via MQTT)