ESP32_Teleplot/ESP32_Teleplot.ino
2024-11-13 22:11:04 +01:00

82 lines
1.8 KiB
C++

#include <WiFi.h>
#include <NetworkUdp.h>
extern const char *ssid;
extern const char *password;
int port;
NetworkUDP udp;
void send_packet(){
udp.beginPacket("teleplot.fr", port);
udp.printf("s:%lu§ms\n", millis() );
udp.printf("cos:%lu:%2.3f\n", millis(), cos(millis()/1000.) );
udp.printf("sin:%lu:%2.3f\n", millis(), sin(millis()/1000.) );
udp.endPacket();
}
void get_network_info(){
if(WiFi.status() == WL_CONNECTED) {
Serial.print("[*] Network information for ");
Serial.println(ssid);
Serial.println("[+] BSSID : " + WiFi.BSSIDstr());
Serial.print("[+] Gateway IP : ");
Serial.println(WiFi.gatewayIP());
Serial.print("[+] Subnet Mask : ");
Serial.println(WiFi.subnetMask());
Serial.println((String)"[+] RSSI : " + WiFi.RSSI() + " dB");
Serial.print("[+] ESP32 IP : ");
Serial.println(WiFi.localIP());
}
}
void setup()
{
// Initialisation de la liaison série
Serial.begin(115200);
delay(1000);
Serial.println("\n");
// Connexion au WiFi
WiFi.persistent(false);
WiFi.begin(ssid, password);
Serial.print("Tentative de connexion...");
while (WiFi.status() != WL_CONNECTED)
{
Serial.print(".");
delay(100);
}
Serial.println("\n");
// Affichage des information de connexion
get_network_info();
Serial.println("\n");
// Attente de la réception du port
Serial.println("Indiquez le port du serveur teleplot:\n");
while(!Serial.available());
// Lecture du port
port=0;
while(Serial.available()){
int chiffre;
chiffre = Serial.read();
if(chiffre < '0' || chiffre > '9'){
break;
}
port = port * 10 + (chiffre - '0');
}
Serial.printf("port lu:%d\n", port);
}
void loop()
{
delay(50);
send_packet();
}