Getting "unknown command" with button onclicksend

Support forum for MegunoLink
Post Reply
griiker
Posts: 19
Joined: Wed Jun 27, 2018 12:27 am

Getting "unknown command" with button onclicksend

Post by griiker » Sun Jul 01, 2018 11:26 pm

I have tried all sorts of things to get this to work. I have tried cutting and pasting the Turtles example, scrutinizing the writing, and structure of the sketch, and I always get an error "unknown command" when I try to send an int variable using the button onclicksend.

What gives?

Here is the code:

/* **********************************************************************************************
this sketch is to monitor and send signals when ceetain parameters are met
* ********************************************************************************************** */
#include "MegunoLink.h"
#include "CommandHandler.h" // The serial command handler is defined in here.

CommandHandler<> SerialCommandHandler;

InterfacePanel Airflowpanel;

#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

// Uncomment if you would like to use plotting channels
// TimePlot MyPlot("Waveforms"); //"Waveforms" = the taget plotting channel (remember to select this in megunolink)

TimePlot MyPlot; //no channel selected
const int meterpin = A0;// pin that the airflow meter is connected to
const int LEDPin = 13; // Pin the LED is attached to
const int CFrun = 3; //the pin the AKTA input is for
const int Fail1 = 12; // this sends the message of test fail/pass to the AKTA
int metervoltage = 0; // the sensor value
int doublemetervoltage = 0;
int testtime = 0;
float digitalcoeff = 0;
float flowrate = 0;
float Ccmvar = 0;
float setpoint = 0;
long starttime = 0;
long runtime = 0;
long trun = 10000;
bool george;
bool paramselect;
String Start = Start;

void Cmd_SetBoolean(CommandParameter &Parameters)
{
Serial.print("Got new boolean:");
paramselect = Parameters.NextParameterAsInteger();
Serial.println(paramselect);
}

void Cmd_Settesttime(CommandParameter &Parameters)
{
testtime = Parameters.NextParameterAsInteger();
}
void setup()
{

pinMode(LEDPin, OUTPUT);
//pinMode (CFrun,INPUT);
pinMode (Fail1, OUTPUT);

Serial.begin(9600);
SerialCommandHandler.AddCommand(F("SetBoolean"), Cmd_SetBoolean);
SerialCommandHandler.AddCommand(F("Time"), Cmd_Settesttime);

MyPlot.SetTitle("Airflow in Cubic Centimeters per minute (Ccm/min)");
MyPlot.SetXlabel("Time");
MyPlot.SetYlabel("Ccm/min");

MyPlot.SetSeriesProperties("flowrate", Plot::Blue, Plot::Solid, 2, Plot::NoMarker);

lcd.begin(16, 2); //Activates and defines the LCD
lcd.clear();
}
void loop()
{
trun=(testtime*60000);
SerialCommandHandler.Process();
//if (CFrun ==HIGH)
if (trun > 0)
{
starttime = millis();

Airflowpanel.SetText("teststatus", "Testing");
digitalWrite (LEDPin, LOW);
digitalWrite (Fail1, LOW);
//digitalRead(CFrun);

if (paramselect)
{
Airflowpanel.DisableControl("sixCcm");
setpoint = 3.00;
Airflowpanel.SetText("alarmsetpoint", setpoint);
SerialCommandHandler.Process();
}

if (!paramselect)
{
setpoint = 6.00;
Airflowpanel.DisableControl("threeCcm");
Airflowpanel.SetText("alarmsetpoint", setpoint);
SerialCommandHandler.Process();
}
if (george)
{
while (runtime < trun)
{

Airflowpanel.SetText("teststatus", "Testing");

//while (CFrun==HIGH)*/

metervoltage = analogRead(meterpin); //read the sensor
doublemetervoltage = 2 * metervoltage;
digitalcoeff = (5 / 1023);
flowrate = 0.00488759 * doublemetervoltage; //(0.00488759=digitalcoeff);
lcd.setCursor(4, 0);
lcd.print(flowrate);
lcd.print(" ccm");

//Send Data To MegunoLink Pro
MyPlot.SendData(F("flowrate"), flowrate); // "flowrate" is series name, flowrate is the actual data value being ploted
Airflowpanel.SetText("flowrate", flowrate);
Airflowpanel.SetText("MeterVoltage", metervoltage);
Airflowpanel.SetText("doublemetervoltage", doublemetervoltage);
digitalWrite (LEDPin, LOW);

if (flowrate <= setpoint)
{
Airflowpanel.SetText("teststatus", "Testing");
}

if (flowrate >= setpoint)
{
digitalWrite(Fail1, HIGH);
digitalWrite(LEDPin, HIGH);
Airflowpanel.SetText("teststatus", "Test Failed");
Airflowpanel.EnableControl("threeCcm");
Airflowpanel.EnableControl("sixCcm");
george = !george;

}

if (runtime >= trun)
{
Airflowpanel.SetText("teststatus", "Test PASSED");
Airflowpanel.EnableControl("threeCcm");
Airflowpanel.EnableControl("sixCcm");
george = !george;
Serial.print("runtime");
Serial.println(runtime);

}
runtime = millis() - starttime;
Serial.print("runtime");
Serial.println(runtime);
delay(1000);

}
}
}

}

philr
Posts: 193
Joined: Mon May 26, 2014 10:58 am

Re: Getting "unknown command" with button onclicksend

Post by philr » Mon Jul 02, 2018 6:23 am

Hi Griiker, program looks good to me and seems to work for me. When i send
"!SetBoolean 1\r" it prints out the message

And when I send
"!Time 10\r" it seems to start sending a bunch of messages.

Did you make sure you put the "!" and "\r"? The command handler needs these to find the start and end of a message respectively.

Cheers
Phil

griiker
Posts: 19
Joined: Wed Jun 27, 2018 12:27 am

Re: Getting "unknown command" with button onclicksend

Post by griiker » Mon Jul 02, 2018 8:00 pm

This is the message I get in the Monitor:

!Settime 1Unknown command
!Settime 1Unknown command

This is the command that is sent: !Settime [Time.Value]\r

and the function:

void Cmd_Settime(CommandParameter &Parameters)
{
testtime = Parameters.NextParameterAsInteger();
Serial.print("testing time " );
Serial.println(testtime);
}
and in the void setup:

SerialCommandHandler.AddCommand(F("Time"), Cmd_Settime);

what am i doing wrong here?

philr
Posts: 193
Joined: Mon May 26, 2014 10:58 am

Re: Getting "unknown command" with button onclicksend

Post by philr » Tue Jul 03, 2018 7:35 am

In the example you gave you have this
SerialCommandHandler.AddCommand(F("Time"), Cmd_Settime);

But it should be
SerialCommandHandler.AddCommand(F("Settime"), Cmd_Settime);
to work. The string (bit in the " ") is the command.

In your example you send the command "Settime" but the command handler is looking for "Time".

Cheers
Phil

griiker
Posts: 19
Joined: Wed Jun 27, 2018 12:27 am

Re: Getting "unknown command" with button onclicksend

Post by griiker » Wed Jul 04, 2018 3:59 am

I see. I will try the fix, let you know how it goes.

Thanks

griiker

griiker
Posts: 19
Joined: Wed Jun 27, 2018 12:27 am

Re: Getting "unknown command" with button onclicksend

Post by griiker » Wed Jul 04, 2018 10:47 pm

unfortunately, as I was expecting, fixing the unalike lines did nothing. The discrepancy is likely the result of me trying various combinations of verbiage trying to get the thing to work. I carefully matched the verbiage of the two lines, and still getting the same "unknown command" message.

I do get a response when I press a button that sends "!Settesttime[testtime.Value]\r" I have a number box "testtime" which I put different number in, so it looks like the communication between the interface panel and arduino is working. so what could it be? what command is it referring to by "unknown command"?

!Settesttime1
Unknown command
!Settesttime1
Unknown command
!Settesttime2
Unknown command
!Settesttime3
Unknown command

void Cmd_SetBoolean(CommandParameter &Parameters)
{
paramselect = Parameters.NextParameterAsInteger();

if (!paramselect)
{
setpoint = 6.00;
Airflowpanel.DisableControl("threeCcm");
Airflowpanel.SetText("alarmsetpoint", setpoint);
george = true;
}
if (paramselect)
{
setpoint = 3.00;
Airflowpanel.DisableControl("sixCcm");
Airflowpanel.SetText("alarmsetpoint", setpoint);
Airflowpanel.SetText("teststatus", "Testing");
george = true;
}
}

void Cmd_Settesttime(CommandParameter &Parameters)
{
testtime = Parameters.NextParameterAsInteger();
Serial.print("testing time " );
Serial.println(testtime);
george = true;
}
void setup()
{
pinMode(LEDPin, OUTPUT);
pinMode (CFrun, INPUT);
pinMode (Fail1, OUTPUT);

Serial.begin(9600);
SerialCommandHandler.AddCommand(F("SetBoolean"), Cmd_SetBoolean);
SerialCommandHandler.AddCommand(F("Settesttime"), Cmd_Settesttime);

philr
Posts: 193
Joined: Mon May 26, 2014 10:58 am

Re: Getting "unknown command" with button onclicksend

Post by philr » Thu Jul 05, 2018 1:01 am

You need a space between the command and parameter.

"!Settesttime 5\r"

Cheers
Phil

griiker
Posts: 19
Joined: Wed Jun 27, 2018 12:27 am

Re: Getting "unknown command" with button onclicksend

Post by griiker » Thu Jul 05, 2018 3:59 am

That's what did it! It was confusing at first to understand where I need to make the change, but finally figured it out in the OnTheClickSend command of tjhe button.

Thanks for the help!

griiker

philr
Posts: 193
Joined: Mon May 26, 2014 10:58 am

Re: Getting "unknown command" with button onclicksend

Post by philr » Thu Jul 05, 2018 8:57 pm

No problem. We would love to figure out a formula for making it easier to understand. What do you think we could do to help going forward?

Cheers
Phil

Post Reply