Created
July 18, 2021 21:42
-
-
Save dj1711572002/7ca7fbbe680265121e57be141433bd1b to your computer and use it in GitHub Desktop.
ESP32_Serve-ESP32_Client UDP Test Program
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <WiFi.h> | |
#include <WiFiUdp.h> | |
const char ssid[] = "ESP32_wifi"; // SSID | |
const char pass[] = "esp32pass"; // password | |
const int localPort = 10000; // ポート番号 | |
const IPAddress ip(192, 168, 4, 1); // IPアドレス(ゲートウェイも兼ねる) | |
const IPAddress subnet(255, 255, 255, 0); // サブネットマスク | |
uint8_t data[1000]; | |
uint8_t dataN[31000];//データ受信データ数 配列 2msec周期なので600sec | |
int i,j,k,n; | |
WiFiUDP udp; | |
void setup() { | |
Serial.begin(115200); | |
n=0; | |
k=0; | |
WiFi.softAP(ssid, pass); // SSIDとパスの設定 | |
delay(100); // 追記:このdelayを入れないと失敗する場合がある | |
WiFi.softAPConfig(ip, ip, subnet); // IPアドレス、ゲートウェイ、サブネットマスクの設定 | |
Serial.print("AP IP address: "); | |
IPAddress myIP = WiFi.softAPIP(); | |
Serial.println(myIP); | |
Serial.println("Starting UDP"); | |
udp.begin(localPort); // UDP通信の開始(引数はポート番号) | |
Serial.print("Local port: "); | |
Serial.println(localPort); | |
} | |
void loop() { | |
j=udp.parsePacket(); | |
if (j>1) | |
{ | |
uint8_t k = udp.read(data,1000); //ceramie追記 askiiから文字列へ | |
Serial.print(",j="); | |
Serial.print(j); | |
Serial.print(","); | |
Serial.print(millis()); | |
Serial.println(",msec"); | |
n++; | |
//dataN[n]=j; | |
} | |
/* | |
// record RecievedData | |
if(j!=999) | |
{ | |
k++; | |
Serial.print(k); | |
Serial.print(":j="); | |
Serial.print(j); | |
Serial.print(","); | |
} | |
*/ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment