ESP32とSimlinkのUDP通信の方法

조회 수: 13 (최근 30일)
Kazuki Hashimoto
Kazuki Hashimoto 2019년 7월 2일
댓글: 昭次 宮西 2020년 10월 30일
ESP32(http://akizukidenshi.com/catalog/g/gM-11819/)からデータを送信し、SimlinkのUDP Receiveブロックを使ってデータを受信しようとしたが、できなかった。
Arduino側のプログラム(この記事を参考にしたhttps://qiita.com/Tsukkey/items/247285c703fbbc6c6cd2)
#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側の設定
iOS の画像.jpg
「Verify address and port connectivity...」は問題なかった。
SimlinkのDisplayに、ESP32から送信した1が表示されると思っていたが、0のまま変わることはなかった。
  댓글 수: 1
昭次 宮西
昭次 宮西 2020년 10월 30일
ESP側に問題があるので、MATLABに聞いても回答を得られないのでは。
ESPのプログラム動作ですが、ポートを開いて、直後に1パケットだけ送って終了と推察しますが、
MATLAB側のポートが準備できる前にパケットが送られているとすれば、この動作になるのでは。

댓글을 달려면 로그인하십시오.

답변 (0개)

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!