I am trying to connect my esp32 to Megunolink, over a wifi network. I used the example EspTcpServerWirelessPlotting, with this code:
Code: Select all
#include "WiFi.h"
#include "MegunoLink.h"
#include <M5Core2.h>
const char *SSID = "XXX";
const char *WiFiPassword = "YYY";
const char *Host = "192.168.1.20";
const unsigned Port = 11000;
WiFiClient Client;
float Timestamps[1];
float Measurements[1];
void ConnectToWiFi()
{
WiFi.mode(WIFI_STA);
WiFi.begin(SSID, WiFiPassword);
Serial.print("Connecting to "); Serial.println(SSID);
uint8_t i = 0;
while (WiFi.status() != WL_CONNECTED)
{
Serial.print('.');
delay(500);
if ((++i % 16) == 0)
{
Serial.println(F(" still trying to connect"));
}
}
Serial.print(F("Connected. My IP address is: "));
Serial.println(WiFi.localIP());
}
WiFiClient *GetClient()
{
if (!Client.connected() && Client.connect(Host, Port))
{
return &Client;
}
return Client.connected() ? &Client : NULL;
}
void setup()
{
Serial.begin(9600);
ConnectToWiFi();
}
void loop()
{
for(int i = 0; i < 1; ++i)
{
analogReadResolution(12);
Timestamps[i] = millis();
float Value = analogRead(36);
Measurements[i] = Value;
delay(1);
}
WiFiClient *pClient = GetClient();
if (pClient != NULL)
{
XYPlot MyPlot("", *pClient);
MyPlot.SendData("Analog Measurements", Timestamps, Measurements, 1, 2);
//Plot.SendData("ADC Value", Value);
}
else
{
Serial.println("TCP Connection failed");
}
// delay(1);
}
I also tried to create a buffer (the for cycle inside the loop) to store a certain number of data, but in this case the transmission time increases.
How can I send my data in a shorter time?
Thank you very much!
Bruno