All Tutorials / Rich / Command Syntax For Data Retrieval

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; However that will return an invalid syntax. If you think about it, that is no different to having a line of code which is; The returned data in the HTTPGet example could be 23, so what...

Controls

This tutorial uses the following controls. Select a control to view the manual page.

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 Smile

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

Code:

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;

Code:

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;

Code:

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



or as part of a function

Code:

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 EZ-Builder 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 Smile



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.

Steps