How can I receive sensor data from Arduino/ESP32 to MATLAB?
71 次查看(过去 30 天)
显示 更早的评论
I'm doing a final project for my school using two sensor that connected to ESP32 as a microcontroller and access point. I want to send the sensor reading from ESP32 through TCP/IP Protocol and receive it in MATLAB. The problem is I don't know how, like I don't even have the code that I've been working on, and I can't find any reference that help me through this problem. When I click run on my matlab code, the ESP32 detected a client, but the readings don't show up. I'm using a randomSeed as the sensor reading for now. Anyone can help me?
This is the Arduino code:
#include <WiFi.h>
#include <WiFiClient.h>
#include <WiFiAP.h>
const char *ssid = "ESP32 AP";
const char *password = "";
WiFiServer server(80);
//float emg1 = 34
//float emg2 = 35
unsigned long to=0;
void setup() {
Serial.begin(115200);
Serial.println();
Serial.println("Configuring access point...");
// You can remove the password parameter if you want the AP to be open.
WiFi.softAP(ssid);
Serial.print("AP IP address: ");
Serial.println(WiFi.softAPIP());
server.begin();
Serial.println("Server started");
randomSeed(analogRead(34));
}
void loop() {
WiFiClient client = server.available();
if (client) {
Serial.println("New Client!");
//String currentLine = "";
while (client.connected()) {
if (client.available()) {
//char c=client.read();
//if(c != 'stop'){
//while(micros()>to+1000){
//to=micros();
int val1 = random(0,50);
int val2 = random(51,100);
Serial.print("val1 = ");
Serial.print(val1);
client.print(val1);
Serial.print(" val2 = ");
Serial.println(val2);
//}
//}
}
}
}
}
This is the MATLAB code:
s=tcpip('192.168.4.1',80,'NetworkRole','client')
fopen(s);
data=fread(s);
1 个评论
franco pizzi
2020-9-27
Hello, I have the same problem and I couldn't solve it. Did you sort out the problem?
回答(2 个)
Laura Gautschi
2021-1-18
Are you working with thingspeak? I guess the best solution is to create a channel on thingspeak.com and then send the data to the channel. You can do this by implicating your channelnumber and Number of the Field where you want the data to appear. Let me know if you are intrested in the full programm?
1 个评论
Krisada Sangpetchsong
2022-2-25
You can try Waijung 2 for ESP32. This allows you to connect ESP32 with Simulink and run in External Mode via Wifi, making it possible to tune Simulink model parameters and monitor signal in real-time.
See this video for the concept https://youtu.be/apSs1dOlFF0
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 WiFi 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!