Logic Machine Forum
How to control the KNX bus via SMS and send notices via SMS? - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: How to control the KNX bus via SMS and send notices via SMS? (/showthread.php?tid=68)

Pages: 1 2 3


RE: How to control the KNX bus via SMS and send notices via SMS? - admin - 03.07.2020

If you want to use API why not use Telegram instead? It's free and easy to configure. See this: https://forum.logicmachine.net/showthread.php?tid=2666&pid=17111#pid17111


RE: How to control the KNX bus via SMS and send notices via SMS? - misterb - 05.01.2023

Hello,

with the instruction and files in post 3 I am now able to receive and send sms. THX!
I also managed to reboot via SMS and get back some information (e.g. IP) when sending a sms with "status" as content to LM.

I now want to get back the signal status of the modem via sms.
ASFAIK the AT-Command "AT+CSQ" delivers this information but unfortunately I have no clue how to implement this (my lua and AT-Command skills are not the best Smile ).

Can anyone help?

Thx in advance!


RE: How to control the KNX bus via SMS and send notices via SMS? - admin - 05.01.2023

1. Modify the user library send function so it returns the command reply/result:
Code:
-- send command to terminal
function AT:send(cmd)
  local res, err = self.port:write(cmd .. '\r\n')
  local reply

  -- write ok, get local echo
  if res then
    res, err = self:readuntil(cmd)
    reply = self:read()
  end

  return res, err, reply
end

2. Add before handler = function(sms) in the resident script:
Code:
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
  end

  csqtime = os.time()

3. Add before udphandler(server) in the resident script:
Code:
now = os.time()
    delta = math.abs(now - csqtime)

    if delta >= 15 then
      csqtime = now
      readcsq()
    end

This will read the signal quality every 15 seconds and will set global variable quality that you can use in the SMS reply message.


RE: How to control the KNX bus via SMS and send notices via SMS? - misterb - 06.01.2023

Works perfect - THX!


RE: How to control the KNX bus via SMS and send notices via SMS? - misterb - 09.01.2023

Is it possible to change APN via SMS and reconnect to the new APN? I am sure it is but my skills ...

I need this to connect to my LM in case the VPN is down.
Normally I use the APN "internet.telekom, tm ,tm" and do not want to change this default setting (bacause of security reasons) - with this APN you get a private WAN-IP like 10.x.x.x and AFAIK you can not connect to private IPs.
With the APN "internet.t-d1.de, internet, t-d1" you get a non private IP like 32.x.x.x and you can connect to it.

Another point: In the resident script the PIN code needs to be set - either as a number or a object-variable. Is it also possible to get the PIN code out of the system preferences where it usually also has to be set?

THX in advance!