Logic Machine Forum
Send data from LM over IP - 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: Send data from LM over IP (/showthread.php?tid=4080)



Send data from LM over IP - Dré - 06.06.2022

I'm using the next script p1-smart-metering for reading out my smart meter over P1 port. This is working fine.

I also want use this data on another server and want sent it over IP.

part of the script to show what i mean. *rule 9 and 16
Code:
if data then
  --log(data)
 
  -- Totaal verbruik tarief 1: nacht- of weekendtarief uitlezen kWh
  tarief_1 = data:match'1.8.1%((%d+.%d+)'
  tarief_1 = tonumber(tarief_1)
--log("Tarief 1 nacht- of weekendtarief: " .. tarief_1 .. " kWh")
  grp.checkupdate('13/0/28', tarief_1)
sent this data over IP on port 19928 (if the value chanced)
       
  -- Totaal verbruik tarief 2: dagtarief uitlezen kWh
  tarief_2 = data:match'1.8.2%((%d+.%d+)'
  tarief_2 = tonumber(tarief_2)
  --log("Tarief 2 dagtarief: " .. tarief_2 .. " kWh")
  grp.checkupdate('13/0/29', tarief_2)
sent this data over IP on port 19929 (if the value chanced)
       

This is the first time i use a IP command.
I hope someone can help me with how to do this.


RE: Send data from LM over IP - admin - 06.06.2022

Is it TCP or UDP? Is there some specific protocol or the value should be sent as a string without any conversion?


RE: Send data from LM over IP - Dré - 06.06.2022

What i want is sent these data to another server with 'Domoticz' aka 'Home Assistent'.
and read this value with these servers.

there is no conversion needed.
UDP is enough


RE: Send data from LM over IP - admin - 06.06.2022

Use this:
Code:
data = tostring(tarief_1)
sock = require('socket').udp()
sock:sendto(data, '192.168.1.204', 19928)
sock:close()



RE: Send data from LM over IP - Dré - 06.06.2022

Yes thanks, it is working