data transmission over TCP

Support forum for MegunoLink
Post Reply
tenere700
Posts: 3
Joined: Sat Apr 10, 2021 8:32 am
Location: Italy

Sun Dec 19, 2021 8:46 am

Dear All,
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);
}
Everything works fine, but the time required for the data transmission is very high (about 10ms). This means that I have a maximum sample rate of 100 samples/s, that is very low.
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
Post Reply