ESP32とSimlinkのUDP通信の方法
6 views (last 30 days)
Show older comments
ESP32(http://akizukidenshi.com/catalog/g/gM-11819/)からデータを送信し、SimlinkのUDP Receiveブロックを使ってデータを受信しようとしたが、できなかった。
#include <WiFi.h>
#include <WiFiUDP.h>
const char ssid[] = "************"; // SSID
const char pass[] = "************"; // password
static WiFiUDP wifiUdp;
static const char *kRemoteIpadr = "192.168.10.4"; //任意
static const int kRmoteUdpPort = 9000; //送信先のポート(任意)
static void WiFi_setup()
{
static const int kLocalPort = 7000; //自身のポート(任意)
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();
}
void loop()
{
wifiUdp.beginPacket(kRemoteIpadr, kRmoteUdpPort);
wifiUdp.write('1');
wifiUdp.endPacket();
delay(1000);
}
Simlink側の設定

「Verify address and port connectivity...」は問題なかった。
SimlinkのDisplayに、ESP32から送信した1が表示されると思っていたが、0のまま変わることはなかった。
1 Comment
昭次 宮西
on 30 Oct 2020
ESP側に問題があるので、MATLABに聞いても回答を得られないのでは。
ESPのプログラム動作ですが、ポートを開いて、直後に1パケットだけ送って終了と推察しますが、
MATLAB側のポートが準備できる前にパケットが送られているとすれば、この動作になるのでは。
Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!