Code:
dummy VAR BYTE
Hits VAR BYTE
Main:
' Issue a module reset
HSEROUT["AT+RST", 13, 10]
' Module should respond with a bunch of data and finally 'ready'
HSERIN[WAIT ("ready"), dummy]
' Set the mode, module may respond differently depending on if it's
' already IN the current mode so we simply delay (not good practise).
HSEROUT["AT+CWMODE=3", 13, 10]
PAUSE 100
' Join the accesspoint, module should respond with 'OK'
' Replave mynetwork and password with actual SSID and password
HSEROUT["AT+CWJAP=", 34, "mynetwork", 34, "," ,34, "password", 34, 13, 10]
HSERIN[WAIT ("OK"), Dummy]
' Allow multiple connections, module should respond with 'OK'
HSEROUT["AT+CIPMUX=1", 13, 10]
HSERIN[WAIT ("OK"), Dummy]
' Open port 80 (normal port for HTTP), module should respond with 'OK'
HSEROUT["AT+CIPSERVER=1,80", 13, 10]
HSERIN[WAIT ("OK"), Dummy]
' Here we need to wait for a client to connect and request data.
' When that happens the module will outout the HTTP header on the
' UART, we'll trig on the GET keyword.
HSERIN[WAIT("GET"), Dummy]
Hits = Hits + 1
' Prepare to send 33 bytes
HSEROUT["AT+CIPSEND=0,33", 13, 10]
PAUSE 100
' Send the actual data
HSEROUT["<TITLE>PBP ESP8266 demo</TITLE>", 13, 10]
PAUSE 100
' Prepare to send 30 bytes
HSEROUT["AT+CIPSEND=0,30", 13, 10]
PAUSE 100
' Send the actual data
HSEROUT["<H1>Testing the ESP8266</H1>", 13, 10]
PAUSE 100
' Prepare to send 22 bytes
HSEROUT["AT+CIPSEND=0,22", 13, 10]
PAUSE 100
' Send the actual data
HSEROUT["<H3>Cool stuff!</H3>", 13, 10]
PAUSE 100
' Prepare to send 18 bytes
HSEROUT["AT+CIPSEND=0,18", 13, 10]
PAUSE 100
' Send the actual data
HSEROUT["Page visits: ",DEC3 Hits, 13, 10]
PAUSE 100
' Now disconnect
HSEROUT["AT+CIPCLOSE=0", 13, 10]
PAUSE 1000
Goto Main
Bookmarks