WiFly RN-XV Client Feature examples
I won't admit as to how long it took me to get this working.
The documentation in the WiFly User Manual has an error in the first Client HTML example (section 13).
It says to "set ip address 0" so WiFly will use DNS, but actually it should be "set ip host 0" so DNS will be used.
Later examples in the section show the correct command. This can lead to some confusion...
I hope these examples may help others. Sending the correct HTTP Request Header lines is critical...obviously!
- Ron
NOTE: I am using the Parallax Serial Terminal to display the output from the Propeller
Here is some sample code to get stock quotes in a comma separated file from Yahoo.com
It returns
This example gets the index.htm file from the root on my local computer running Microsoft IIS 5.1 web server
The documentation in the WiFly User Manual has an error in the first Client HTML example (section 13).
It says to "set ip address 0" so WiFly will use DNS, but actually it should be "set ip host 0" so DNS will be used.
Later examples in the section show the correct command. This can lead to some confusion...
I hope these examples may help others. Sending the correct HTTP Request Header lines is critical...obviously!
- Ron
NOTE: I am using the Parallax Serial Terminal to display the output from the Propeller
Here is some sample code to get stock quotes in a comma separated file from Yahoo.com
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
' ------- Pin assigments ------
xv_rx = 13 ' RN-XV Receive Data
xv_tx = 12 ' RN-XV Transmit Data
xv_connect = 11 ' GPIO 6 - HIGH when connected over TCP
xv_port = 0
Var
long useser ' USB serial connection detected T/F
long debugsw ' control output to Parallax Terminal
long stack[50]
OBJ
Debug : "FullDuplexSerial"
WiFly : "FullDuplexSerial"
Pub Main
useser := false
if ina[31] == 1 ' RX (pin 31) is high if USB is connected
Debug.start(31, 30, 0, 57600) ' ignore tx echo on rx
useser := true ' Debug serial connection is active
debugsw := true
else
outa[30] := 0 ' Force Propeller Tx line LOW if USB not connected
if debugsw == true
Debug.str(string(16,"RovingNetworks RN-XV WiFly",13)) 'CLS, msg
WiFly.start(xv_rx,xv_tx,0,9600)
cognew(WiFly_to_PC,@stack) ' Start cog for RN-XV --> PC comms
Delay (2000) ' two second delay
Client_Setup
delay(500)
WiFly.str(string("GET /d/quotes.csv?f=sl1c1&s=goog,scg",10))
WiFly.str(string("Host: download.finance.yahoo.com",10))
WiFly.str(string("Connection: close",10))
PUB Client_Setup
WiFly.str(string("$$$"))
Delay(500)
WiFly.str(string("set ip proto 18",13)) 'enable html client
' bytefill(@tbuff, 0, maxbuff)
WiFly.str(string("set ip address 0",13)) 'DHCP will assign IP address
WiFly.str(string("set ip host 0",13)) 'so WiFly will use DNS
WiFly.str(string("set dns name download.finance.yahoo.com",13))
WiFly.str(string("set ip remote 80",13)) 'set host port number
WiFly.str(string("set comm remote 0",13)) 'turn off the REMOTE string to prevent interference with post
' WiFly.str(string("get dns",13))
WiFly.str(string("open",13))
PUB Delay(mS) ' Delay in milliseconds
waitcnt(clkfreq / 1000 * mS + cnt)
Pub WiFly_to_PC
WiFly.rxFlush ' Empty buffer for data from RN-XV
repeat
debug.tx(WiFly.rx) ' Accept data from RN-XV and send to PC
It returns
"GOOG",641.33,+12.58 "SCG",49.34,+0.77
This example gets the index.htm file from the root on my local computer running Microsoft IIS 5.1 web server
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
' ------- Pin assigments ------
xv_rx = 13 ' RN-XV Receive Data
xv_tx = 12 ' RN-XV Transmit Data
xv_connect = 11 ' GPIO 6 - HIGH when connected over TCP
xv_port = 0
Var
long useser ' USB serial connection detected T/F
long debugsw ' control output to Parallax Terminal
long stack[50]
OBJ
Debug : "FullDuplexSerial"
WiFly : "FullDuplexSerial"
Pub Main
useser := false
if ina[31] == 1 ' RX (pin 31) is high if USB is connected
Debug.start(31, 30, 0, 57600) ' ignore tx echo on rx
useser := true ' Debug serial connection is active
debugsw := true
else
outa[30] := 0 ' Force Propeller Tx line LOW if USB not connected
if debugsw == true
Debug.str(string(16,"RovingNetworks RN-XV WiFly",13)) 'CLS, msg
WiFly.start(xv_rx,xv_tx,0,9600)
cognew(WiFly_to_PC,@stack) ' Start cog for RN-XV --> PC comms
Delay (2000) ' two second delay
Client_Setup
delay(500)
' WiFly.str(string("GET /Hobby/echo.shtml HTTP/1.1",10))
WiFly.str(string("GET /index.htm HTTP/1.1",10))
WiFly.str(string("Host: 192.168.1.100",10))
WiFly.str(string("Connection: close",10))
PUB Client_Setup
WiFly.str(string("$$$"))
Delay(500)
WiFly.str(string("set ip proto 18",13))
WiFly.str(string("set ip address 0",13))
WiFly.str(string("set ip host 192.168.1.100",13))
WiFly.str(string("set dns name 0",13))
WiFly.str(string("set ip remote 80",13))
WiFly.str(string("set comm remote 0",13))
WiFly.str(string("open",13))
' WiFly.str(string("exit",13))
PUB Delay(mS) ' Delay in milliseconds
waitcnt(clkfreq / 1000 * mS + cnt)
Pub WiFly_to_PC
WiFly.rxFlush ' Empty buffer for data from RN-XV
repeat
debug.tx(WiFly.rx) ' Accept data from RN-XV and send to PC

Comments
// [ { "id": "30822" ,"t" : "SCG" ,"e" : "NYSE" ,"l" : "49.34" ,"l_cur" : "49.34" ,"s": "0" ,"ltt":"4:01PM EDT" ,"lt" : "Aug 3, 4:01PM EDT" ,"c" : "+0.77" ,"cp" : "1.59" ,"ccol" : "chg" } ]Spin code (NOTE: putting "HTTP/1.1" in the GET request will not work here for some reason)
CON _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 ' ------- Pin assigments ------ xv_rx = 13 ' RN-XV Receive Data xv_tx = 12 ' RN-XV Transmit Data xv_connect = 11 ' GPIO 6 - HIGH when connected over TCP xv_port = 0 Var long useser ' USB serial connection detected T/F long debugsw ' control output to Parallax Terminal long stack[50] OBJ Debug : "FullDuplexSerial" WiFly : "FullDuplexSerial" Pub Main useser := false if ina[31] == 1 ' RX (pin 31) is high if USB is connected Debug.start(31, 30, 0, 57600) ' ignore tx echo on rx useser := true ' Debug serial connection is active debugsw := true else outa[30] := 0 ' Force Propeller Tx line LOW if USB not connected if debugsw == true Debug.str(string(16,"RovingNetworks RN-XV WiFly",13)) 'CLS, msg WiFly.start(xv_rx,xv_tx,0,9600) cognew(WiFly_to_PC,@stack) ' Start cog for RN-XV --> PC comms Delay (2000) ' two second delay Client_Setup delay(500) WiFly.str(string("GET /finance/info?client=ig&q=SCG",10)) WiFly.str(string("Host: finance.google.com",10)) ' WiFly.str(string("Content-Type: text/xml",10)) WiFly.str(string("Connection: close",10)) PUB Client_Setup WiFly.str(string("$$$")) Delay(500) WiFly.str(string("set ip proto 18",13)) 'enable html client ' bytefill(@tbuff, 0, maxbuff) WiFly.str(string("set ip address 0",13)) 'DHCP will assign IP address WiFly.str(string("set ip host 0",13)) 'so WiFly will use DNS WiFly.str(string("set dns name finance.google.com",13)) WiFly.str(string("set ip remote 80",13)) 'set host port number WiFly.str(string("set comm remote 0",13)) 'turn off the REMOTE string to prevent interference with post ' WiFly.str(string("get dns",13)) WiFly.str(string("open",13)) PUB Delay(mS) ' Delay in milliseconds waitcnt(clkfreq / 1000 * mS + cnt) Pub WiFly_to_PC WiFly.rxFlush ' Empty buffer for data from RN-XV repeat debug.tx(WiFly.rx) ' Accept data from RN-XV and send to PC