Skip to content

Instantly share code, notes, and snippets.

@dj1711572002
Created July 18, 2021 21:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dj1711572002/2e054faa4a89bed895deb1c818a2fafc to your computer and use it in GitHub Desktop.
Save dj1711572002/2e054faa4a89bed895deb1c818a2fafc to your computer and use it in GitHub Desktop.
ESP32_Serve-ESP32_Client UDP Test Program-Server-
#include <WiFi.h>
#include <WiFiUdp.h>
const char ssid[] = "ESP32_wifi"; // SSID
const char pass[] = "esp32pass"; // password
static WiFiUDP wifiUdp;
static const char *kRemoteIpadr = "192.168.4.1"; //送信先のIPアドレス
static const int kRmoteUdpPort = 10000; //送信先のポート
uint8_t tim[1000];
int i;
static void WiFi_setup()
{
static const int kLocalPort = 5000; //自身のポート
WiFi.begin(ssid, pass);
while( WiFi.status() != WL_CONNECTED) {
delay(500);
}
wifiUdp.begin(kLocalPort);
}
static void Serial_setup()
{
Serial.begin(115200);
Serial.println(""); // to separate line
}
void setup() {
Serial_setup();
WiFi_setup();
for (i=0;i<1000;i++)
{
tim[i]=i%255;
Serial.print("tim[");
Serial.print(i);
Serial.print("]=");
Serial.println(tim[i]);
}
}
void loop()
{
wifiUdp.beginPacket(kRemoteIpadr, kRmoteUdpPort);
wifiUdp.write(tim,999); //10進数のASCiiで送信される
wifiUdp.endPacket();
delay(1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment