Command Syntax For Data Retrieval

Description

It seems a lot of people are getting a little confused over the script commands for receiving data and have noticed the syntax is incorrect. So it's tutorial time again:)

Basically, the common mistake is to assume the command for receiving ADC, HTTP etc. data is like;

HTTPGet("http://192.168.0.100/temp.cgi")

However that will return an invalid syntax.

If you think about it, that is no different to having a line of code which is;

23

The returned data in the HTTPGet example could be 23, so what...

Step 1

It seems a lot of people are getting a little confused over the script commands for receiving data and have noticed the syntax is incorrect. So it's tutorial time again:)

Basically, the common mistake is to assume the command for receiving ADC, HTTP etc. data is like;

HTTPGet("http://192.168.0.100/temp.cgi")

However that will return an invalid syntax.

If you think about it, that is no different to having a line of code which is;

23

The returned data in the HTTPGet example could be 23, so what use is 23 on it's own? You have to remember that all get/fetch commands should be looked at as though they are data and not commands. The data alone will be of no use if not used as part of a process or stored as a variable for later use.

The correct syntax would be;

$temp = HTTPGet("http://192.168.0.100/temp.cgi")

or as part of a function

IF(HTTPGet("http://192.168.0.100/temp.cgi") > 23)
  SayWait("Man, it's hot in here!")
ElseIf(HTTPGet("http://192.168.0.100/temp.cgi") < 18)
  SayWait("Brrrr, it's cold in here!")
Else
  SayWait("It''s perfect in here")
EndIf

The same applies to all commands that will fetch data from somewhere including; GetPWM GetServo GetServoSpeed GetSpeed GetSpeedLeft GetSpeedRight GetCPUTemp GetVoltage GetADC GetRandom GetRandomUnique GetDigital GetPing HTTPGet GetChatAt GetByteAt GetByte GetAsByte GetBit GetVolume I2CRead UARTRead FileReadEnd FileReadChar FileReadLine FileReadAll FileReadLineRandom

And possibly more, I think I listed them all but with ARC updates so often it probably wont stay that way.

If you get a syntax error read the help on the right of the script dialogue, there are always examples:)

Update: That said, HTTPGet() will work without assigning variables etc. since it can be used to operate devices and websites etc. such as NotifyMyAndroid. However if used to return data it must be assigned to a variable or used as part of an operation/process.


ARC Pro

Upgrade to ARC Pro

Take control of your robot's destiny by subscribing to Synthiam ARC Pro, and watch it evolve into a versatile and responsive machine.