Test 1: Send empty GET, receive GMT
The first test is the simplest. It uses a DoGet command to the SX10509 to make the SX10509 send a GET request to the server. The query string is empty (i.e. no query string). The server responds with an HTTP status code and the GMT time. The status code is seen by the SPLat program as a response to the DoGet command to the SX10509. The GMT time is retrieved from the SX10509’s network Rx buffer using a Read command.
The code checks that the status code is 200. If it is, all is well, and it reads out from the SX10509, and displays, the data returned by the server. If the code is not 200, something went wrong, and the program gives up that test. The sandbox page lets you generate a dummy 299 code, so you can test your program’s ability to detect and handle errors.
Send the GET
The first 6 lines of the Test1 code force the SX10509 to idle, clear its network Tx buffer (so the query string will be empty) and generate a GET request to the server. The server address used is the one from the server tab of the SX10509 configuration page. After each command is sent to the SX10509, the program waits for the sSCH_GotEcho semaphore to get set, at which time (and not before!) it is safe to send another command:
Test1:
GoSub SCH_Idle ;Force the SCH into idle
WaitForST sSCH_GotEcho ;Wait for the command to be echoed
GoSub SCH_ClearTx ;Make sure the SX10509 Tx buffer is clear
WaitForST sSCH_GotEcho ;Wait for the command to be echoed
GoSub SCH_Get ;Send a GET request to the server
WaitForST sSCH_GotEcho ;Wait for the command to be echoed
Retrieve and check the returned status code
When the server has responded to the GET request, the status code can be found in the network Rx data block as a floating point number. The next bit of code retrieves the code and tests if it is 200 (good) or anything else (bad). If it is good it jumps to program line Test1a. If the code is bad, the program displays a message on the LCD and loops back to WAFbutton to wait for another button press.
fRecallW abRxData ;Get the status code -> W
fLoadQ 200 ;OK code
fTestWeqQ ;OK?
GoIfT Test1a ;g/ good response
OBLCD_Cls ;Display the bad status code
;0123456789012345
OBLCD_Text "Error code "
OBLCD_fDispW 3,0
GoTo WAFButton
Display the returned string
The data returned from the server is an ASCII string. It is currently sitting in the SX10509 network Rx buffer. To display it we first read it from the SX10509 to the Xwire Rx data block, then use a subroutine (one we prepared earlier) to display it.
Test1a:
LoadI 0 ;Offset into SCH network Rx buffer
GoSub SCH_Read ;Read the SCH Rx buffer to the Xwire Rx data block
WaitForST sSCH_GotEcho ;Wait for the command to be echoed
GoSub RxDisplay ;Display the result
GoTo WAFbutton
In this case we only need to read once from the SX10509 network Rx buffer, because we know it will have fewer characters for us than can fit in our Xwire Rx data block. The parameter I = 0 that we send to SCH_Read causes the read to be taken from the start of the SX10509 network Rx buffer.
Note: The GMT time in this example is formatted and supplied by the sandbox php code as an ASCII (human readable) text string. This is quite different to the built in Time and Date functions of the SX10509 board, which use an Internet time server and return the data to the SPLat board in a binary (non human-readable) format. The sandbox example does not use that feature of the SX10509