Page 1 of 1

sending values to Gauge

Posted: Sun Jan 29, 2023 12:01 pm
by ElectricRay1981
When I try to send data to the Gauge I keep having the message AddCommand: full. When I directly send a number in the Arduino sketch it works fine but when I attach a variable it doesn't work. Does anybody knows what I am doing wrong?

Code: Select all

void loop() {
  SerialCmds.Process();                                             //Monitor serial commands
  if (timeOut(250)) {  // 4 Hz update frequency
    cli(); //stop interrupts
    prevPulseUsCopy = prevPulseUs;
    pulseUsCopy = pulseUs;
    sei(); //allow interrupts
    pulsePeriod = pulseUsCopy - prevPulseUsCopy;
    if (pulsePeriod) rpm = 20 + slotUs / pulsePeriod ;
    Serial.println(rpm);
    
    SerialCmds.AddCommand(F("GetSpeed"),Cmd_SendSpeedRightMotor);
  }

}

void Cmd_SendSpeedRightMotor(CommandParameter& p)
{
    InterfacePanel MyPanel;
          
  // Set control value
  MyPanel.SetNumber(F("IPGauge2"), rpm);
}
Above the part of my code that should send the value rpm to Megunolink. rpm is a integer. I hope someone knows what I am doing wrong.

Re: sending values to Gauge

Posted: Wed Feb 01, 2023 8:11 am
by philr
Hi, can you post the rest of your program?

You should only add the command handler once in the setup part of your program. Not in the loop part.

Re: sending values to Gauge

Posted: Sun Feb 05, 2023 2:47 pm
by ElectricRay1981
Sorry for the late reply I did not receive a notification (I found the checkbox now). I was able to make it work over serial connection but when creating a WiFi connection I'm unable to send data to the gauge wireless.

Code: Select all

/* ******************************************************************

#include <TCPCommandHandler.h>
#include <CommandHandler.h>
#include "CommandProcessor.h"
#include <MegunoLink.h>
#include <WiFi.h>
 

const char *SSID = "My SSID";
const char *WiFiPassword = "My PSWD";

 
const char *Host = "Desktop IP";
const unsigned Port = 11000;
 
WiFiClient Client;

InterfacePanel MyPanel; 
CommandHandler<> SerialCmds;


 
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 SendMeasurement(unsigned Value)
{
  WiFiClient *pClient = GetClient();
 
  if (pClient != NULL)
  {
      MyPanel.SetNumber(F("RightSpeedGauge"), 1);
  }
  else
  {
    Serial.println("TCP Connection failed");
  }
}
 
void setup() 
{
  Serial.begin(9600);
 
  ConnectToWiFi();
}
 
void loop() 
{
  SerialCmds.Process(); 
  unsigned Measurement = 10;
  SendMeasurement(Measurement);
 
  delay(1000);
}
As you can see I tried to use the example from the documention but appearently I use it the wrong way. Not sure what to do, I was hoping that the command

Code: Select all

MyPanel.SetNumber(F("RightSpeedGauge"), 1);
would send a value of 1 to the gauge over WiFi connection.
When I ping the ESP32 I get a response so it is connected to the network. How should I fix this?

Thanks in advance