Last active
December 25, 2021 04:02
-
-
Save tuo/67b6826971d63fd5fba7f81795083c2d to your computer and use it in GitHub Desktop.
sim800_http test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ---- Create new software UART with baudrate of 9600, D2 as Tx pin and D3 as Rx pin | |
| function writeCMD(s, cmd) | |
| print("\n"..tostring(tmr.now())..": send cmd", cmd); | |
| s:write(cmd.."\n"); | |
| end | |
| function sim_setup() | |
| if not s then | |
| print("\n"..tostring(tmr.now())..": initilized su\n"); | |
| s = softuart.setup(9600, 2, 3) | |
| s:on("data", "\n", function(data) | |
| local txt = string.gsub(data, "[\r\n]", "") | |
| print("\n"..tostring(tmr.now())..": receive from uart:", txt) | |
| end) | |
| end | |
| end | |
| function sim_send(txt) | |
| writeCMD(s, 'AT+SAPBR=3,1,"Contype","GPRS"') | |
| writeCMD(s, 'AT+SAPBR=3,1,"APN","CMNET"') | |
| writeCMD(s, 'AT+SAPBR=1,1') | |
| writeCMD(s, 'AT+SAPBR=2,1') | |
| writeCMD(s, 'AT+HTTPINIT') | |
| writeCMD(s, 'AT+HTTPPARA="CID",1') | |
| local url = "http://xxxx.com/api?time="..tostring(tmr.now().."&txt="..txt) | |
| writeCMD(s, 'AT+HTTPPARA="URL","'..url..'"') | |
| writeCMD(s, 'AT+HTTPACTION=0') | |
| s:write(0x1a); | |
| end | |
| function sim_call() | |
| writeCMD(s, 'ATD186xxxx5235;') | |
| end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment