#picaxe 20m2
#no_data
'#no_table
#terminal 19200
#define verboseOut
#rem
Fast power up, post data, receive response, power down for ESP8266
#endrem
setfreq m16
'constants
symbol cMode = 1 '1=station, 2=AP, 3=station and AP
symbol cMux = 1 '0=single connection channel, 1=multiple connection channels
symbol cChannel = 0 'channel ID
symbol cUID = 345 'unique ID for PICAXE
symbol cComms = T9600_16 'true comms
symbol cTimeout = 20000 '5 seconds @ 16mhz
'variables
symbol vStep = b19 'case step
symbol vConfirmLoop = b20 'number of loops for confirm message check
symbol vConfirmVar1 = b22 'first byte of confirm message (like OK or no) to look for
symbol vConfirmVar2 = b23 '2nd byte of confirm message to look for
'pins
symbol pRX = B.0 'connect to TX on ESP8266
symbol pTX = B.1 'connect to RX on ESP8266
pause 2000 '1/2 second @ 16mhz
#ifdef verboseOut
sertxd (13,10,"Powered up.",13,10)
#endif
vStep = 0 'start at case step 0
do
vConfirmLoop = 0
main:
select case vStep
case 0
vConfirmVar1 = "n" 'no change
vConfirmVar2 = "o"
#ifdef verboseOut
sertxd ("Set Mode")
#endif
serout pTX,cComms,("AT+CWMODE=",#cMode,13,10)
gosub confirmCMD
case 1
vConfirmVar1 = "O" 'OK
vConfirmVar2 = "K"
#ifdef verboseOut
sertxd ("Connecting")
#endif
serout pTX,cComms,("AT+CWJAP=",34,"ap ssid here",34,",",34,"ap password here",34,13,10)
gosub confirmCMD
case 2
#ifdef verboseOut
sertxd ("Set Mux")
#endif
serout pTX,cComms,("AT+CIPMUX=",#cMux,13,10)
gosub confirmCMD
case 3
#ifdef verboseOut
sertxd ("Send Start")
#endif
serout pTX,cComms,("AT+CIPSTART=",#cChannel,34,"TCP",34,",",34,"www.your webserver here.com",34,",80",13,10)
gosub confirmCMD
case 4
#ifdef verboseOut
sertxd ("Send Length")
#endif
serout pTX,cComms,("AT+CIPSEND=",#cChannel,",44",13,10)
#ifdef verboseOut
sertxd (", Send GET")
#endif
serout pTX,cComms,("GET http://www.your webserver here.com/req.cfm?key=",#cUID,13,10)
serin [cTimeout,main],pRX,cComms,("ZZZ"),b0,b1,b2,b3 'qualifier "ZZZ", the next few chars will be : & config values
sertxd (" OK",13,10,"Data",b0," ",b1,b2,b3,13,10)
if b0 = ":" then
#ifdef verboseOut
sertxd ("Close Conn")
#endif
serout pTX,cComms,("AT+CIPCLOSE=",#cChannel,13,10)
gosub confirmCMD
endif
end 'stop program and put PICAXE in low power mode
end select
loop
end
confirmCMD:
inc vConfirmLoop
if vConfirmLoop < 4 then
#ifdef verboseOut
sertxd (".") 'output waiting indicator
#endif
serin [cTimeout,confirmCMD],pRX,cComms,(vConfirmVar1,vConfirmVar2) 'wait for qualifiers
#ifdef verboseOut
sertxd(" ",vConfirmVar1,vConfirmVar2,13,10) 'show msg indicating command was confirmed successfully
#endif
inc vStep
vConfirmLoop = 0
endif
return