Skip to content

Instantly share code, notes, and snippets.

@tuo
Last active Dec 25, 2021
Embed
What would you like to do?
sim800_http test
---- 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