This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

gsm signal
#1
HI

I followed the instructions I found in the forum on how to evaluate the modem signal, I modified the user and sms (resident) scripts as recommended, now how can I read the global variable quality to be able to represent it in visual display?
is it stored in storage?

A thousand thanks
Reply
#2
Add grp.update like in this script (line #119): https://forum.logicmachine.net/showthrea...4#pid31874
Reply
#3
(18.04.2024, 09:33)admin Wrote: Add grp.update like in this script (line #119): https://forum.logicmachine.net/showthrea...4#pid31874

This is my script code

I have try to log the varibale quality but log nothing ???

Code:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
-- init if not numbers then   require('user.sms')   require('json')   require('socket')   -- allowed numbers, SMS from other numbers will be ignored   numbers = { '3332958126' }   -- port number depends on modem model   comport = 'ttyUSB2'   doreset = false -- set to true if USB reset is required before starting any communication   -- if SIM PIN is enabled, uncomment the line below and replace 0000 with SIM PIN   -- pincode = '0000'   -- command parser   parser = function(cmd, sender)     local find, pos, name, mode, offset, value, dvalue, obj, message     cmd = cmd:trim()     mode = cmd:sub(1, 1):upper()     -- invalid request     if mode ~= 'W' and mode ~= 'R' then       return     end     cmd = cmd:sub(3):trim()     -- parse object name/address     find = cmd:sub(1, 1) == '"' and '"' or ' '     offset = find == '"' and 1 or 0     -- pad with space when in read mode     if mode == 'R' and find == ' ' then       cmd = cmd .. ' '     end     -- find object name     pos = cmd:find(find, 1 + offset, true)     -- name end not found, stop     if not pos then       return     end     -- get name part     name = cmd:sub(1 + offset, pos - offset):trim()     if mode == 'W' then       value = cmd:sub(pos + offset):trim()       if #value > 0 then         -- try decoding value         dvalue = json.pdecode(value)         if dvalue ~= nil then           value = dvalue         end         -- send to bus         grp.write(name, value)       end     -- read request     else       obj = grp.find(name)       -- object not known       if not obj then         return       end       -- send read request and wait for an update       obj:read()       os.sleep(1)       -- read new value       value = grp.getvalue(name)       -- got no value       if value == nil then         return       end       -- add object name if specified       if obj.name then         name = string.format('%s (%s)', obj.name, obj.address)       end       message = string.format('Value of %s is %s', name, json.encode(value))       modem:sendsms('+' .. sender, message)     end   end   -- incoming sms handler     readcsq = function()     local res, err, reply = modem:send('AT+CSQ')     local rssi     if reply then       rssi = reply:match('%+CSQ:%s+(%d+),(%d+)')     end     rssi = tonumber(rssi) or 0     if 2 <= rssi and rssi <= 9 then       quality = 'marginal'     elseif 10 <= rssi and rssi <= 14 then       quality = 'ok'     elseif 15 <= rssi and rssi <= 19 then       quality = 'good'     elseif 20 <= rssi and rssi <= 30 then       quality = 'excellent'     else       quality = 'unknown'     end     grp.write('32/0/0', quality-- Modem signal level write to group   end   csqtime = os.time()   handler = function(sms)     --alert('incoming sms: [%s] %s', tostring(sms.sender), tostring(sms.data))     -- sms from known number, call parser     if table.contains(numbers, sms.sender) then       --parser(sms.data, sms.sender)     end   end     now = os.time()     delta = math.abs(now - csqtime)     if delta >= 15 then       csqtime = now       readcsq()     end     -- check local udp server for messages to send   udphandler = function(server)     -- check for local sms to send     local msg = server:receive()     -- got no message     if not msg then       return     end     -- split into number and message     local sep = msg:find(' ')     if not sep then       return     end     --alert('sending sms: ' .. msg)     modem:sendsms(msg:sub(1, sep - 1), msg:sub(sep + 1))   end end -- handle data from modem if modem then   if modem:run() then     udphandler(server)   else     --alert('SMS handler lost connection')     modem:reinit()   end -- modem init else   --alert('SMS handler init')   -- open serial port   modem = AT:init('/dev/' .. comport, doreset)   -- init ok   if modem then     -- set sms handler     modem:setsmshandler(handler)     -- send pin if set     if pincode then       modem:send('AT+CPIN=' .. pincode)       modem:read()     end     -- set to pdu mode     modem:send('AT+CMGF=0')     -- enable sms notifications     modem:send('AT+CNMI=1,1,0,0,0')     -- fixup encoding     modem:send('AT+CSCS="GSM"')     -- delete all saved messages     modem:send('AT+CMGD=1,4')     -- local udp server for sending sms     server = socket.udp()     server:setsockname('127.0.0.1', 12535)     server:settimeout(0.1)     --alert('SMS handler started')   -- init failed   else     --alert('SMS USB init failed')   end end
Reply
#4
Try this:
Code:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
-- init if not numbers then   require('user.sms')   require('json')   require('socket')   -- allowed numbers, SMS from other numbers will be ignored   numbers = { '3332958126' }   -- port number depends on modem model   comport = 'ttyUSB2'   doreset = false -- set to true if USB reset is required before starting any communication   -- if SIM PIN is enabled, uncomment the line below and replace 0000 with SIM PIN   -- pincode = '0000'   -- command parser   parser = function(cmd, sender)     local find, pos, name, mode, offset, value, dvalue, obj, message     cmd = cmd:trim()     mode = cmd:sub(1, 1):upper()     -- invalid request     if mode ~= 'W' and mode ~= 'R' then       return     end     cmd = cmd:sub(3):trim()     -- parse object name/address     find = cmd:sub(1, 1) == '"' and '"' or ' '     offset = find == '"' and 1 or 0     -- pad with space when in read mode     if mode == 'R' and find == ' ' then       cmd = cmd .. ' '     end     -- find object name     pos = cmd:find(find, 1 + offset, true)     -- name end not found, stop     if not pos then       return     end     -- get name part     name = cmd:sub(1 + offset, pos - offset):trim()     if mode == 'W' then       value = cmd:sub(pos + offset):trim()       if #value > 0 then         -- try decoding value         dvalue = json.pdecode(value)         if dvalue ~= nil then           value = dvalue         end         -- send to bus         grp.write(name, value)       end     -- read request     else       obj = grp.find(name)       -- object not known       if not obj then         return       end       -- send read request and wait for an update       obj:read()       os.sleep(1)       -- read new value       value = grp.getvalue(name)       -- got no value       if value == nil then         return       end       -- add object name if specified       if obj.name then         name = string.format('%s (%s)', obj.name, obj.address)       end       message = string.format('Value of %s is %s', name, json.encode(value))       modem:sendsms('+' .. sender, message)     end   end   -- incoming sms handler     readcsq = function()     local res, err, reply = modem:send('AT+CSQ')     local rssi     if reply then       rssi = reply:match('%+CSQ:%s+(%d+),(%d+)')     end     rssi = tonumber(rssi) or 0     if 2 <= rssi and rssi <= 9 then       quality = 'marginal'     elseif 10 <= rssi and rssi <= 14 then       quality = 'ok'     elseif 15 <= rssi and rssi <= 19 then       quality = 'good'     elseif 20 <= rssi and rssi <= 30 then       quality = 'excellent'     else       quality = 'unknown'     end     grp.write('32/0/0', quality)  -- Modem signal level write to group   end   csqtime = os.time()   handler = function(sms)     --alert('incoming sms: [%s] %s', tostring(sms.sender), tostring(sms.data))     -- sms from known number, call parser     if table.contains(numbers, sms.sender) then       --parser(sms.data, sms.sender)     end   end   -- check local udp server for messages to send   udphandler = function(server)     -- check for local sms to send     local msg = server:receive()     -- got no message     if not msg then       return     end     -- split into number and message     local sep = msg:find(' ')     if not sep then       return     end     --alert('sending sms: ' .. msg)     modem:sendsms(msg:sub(1, sep - 1), msg:sub(sep + 1))   end end -- handle data from modem if modem then   if modem:run() then     udphandler(server)     now = os.time()     delta = math.abs(now - csqtime)     if delta >= 15 then       csqtime = now       readcsq()     end   else     --alert('SMS handler lost connection')     modem:reinit()   end -- modem init else   --alert('SMS handler init')   -- open serial port   modem = AT:init('/dev/' .. comport, doreset)   -- init ok   if modem then     -- set sms handler     modem:setsmshandler(handler)     -- send pin if set     if pincode then       modem:send('AT+CPIN=' .. pincode)       modem:read()     end     -- set to pdu mode     modem:send('AT+CMGF=0')     -- enable sms notifications     modem:send('AT+CNMI=1,1,0,0,0')     -- fixup encoding     modem:send('AT+CSCS="GSM"')     -- delete all saved messages     modem:send('AT+CMGD=1,4')     -- local udp server for sending sms     server = socket.udp()     server:setsockname('127.0.0.1', 12535)     server:settimeout(0.1)     --alert('SMS handler started')   -- init failed   else     --alert('SMS USB init failed')   end end
Reply
#5
nothing return nil from rssi
but not possible message sms work fine
Reply
#6
Log the raw reply (around line 97):
Code:
12
local res, err, reply = modem:send('AT+CSQ') log(res, err, reply)
Reply
#7
(18.04.2024, 11:11)admin Wrote: Log the raw reply (around line 97):
Code:
12
local res, err, reply = modem:send('AT+CSQ') log(res, err, reply)

Yes found problem in this line

as always thank you very much
Reply


Forum Jump: