Automatic Ethernet connection checking and informing in case of troubles ? - Printable Version +- Logic Machine Forum (https://forum.logicmachine.net) +-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1) +--- Forum: General (https://forum.logicmachine.net/forumdisplay.php?fid=2) +--- Thread: Automatic Ethernet connection checking and informing in case of troubles ? (/showthread.php?tid=2304) |
Automatic Ethernet connection checking and informing in case of troubles ? - demeur - 25.10.2019 I can read "Automatic Ethernet connection checking and informing in case of troubles" in the LM5 description. ( what means ?) Is it a already function who the logic machine can send to me "i am up and all is ok" when it is connected to ethernet ? it use cloud service of logic machine ? how can i use it ? Best Regard. RE: Automatic Ethernet connection checking and informing in case of troubles ? - Joep - 05.11.2019 You can check some network futures yourself with the script below and do with it whatever you like. Run it as an init scrit and send an email with this information for example. Have fun with it require('json') require('socket.http') ip = io.readproc('if-json') ip = json.decode(ip) log("IP address: " ..ip.eth0.inetaddr) socket.http.timeout = 5 data = socket.http.request('http://ip-api.com/json') if data then data = json.decode(data) log("WAN IP: "..data.query) log("City: "..data.city) log("Region: "..data.region) log("Country: "..data.countryCode) log("Latitude: "..data.lat) log("Longitude: "..data.lon) else log("There is possible no internet connection") end log("DNS name: " ..socket.dns.gethostname()) io.input("/sys/class/net/eth0/carrier") carrier = io.read("*line") if carrier == "1" then log("Connected to the network") else log("No connection to the network") end io.input("/sys/class/net/eth0/operstate") state = io.read("*line") if state == "up" then log("The network connection is active") else log("The network connection is inactive") end RE: Automatic Ethernet connection checking and informing in case of troubles ? - Erwin van der Zwart - 05.11.2019 Hi Joep, welcome at the forum, took you a loooooooong time to join (: The question was to send “I’m okay” but I don’t see the added value in that, I would want to know when it’s not okay anymore and that’s a bit tricky when you don’t have internet (: SMS could help you in that case or check the controller from another device. If you want the okay message on interval bases you could simply add a scheduled script with a single command mail('me@gmail.com', 'Controller X status', 'I’m okay') as it will be send when connection is there (: But after a few days of mail you will get crazy of those spam messages and you will start ignore them so what’s the point of adding it in the first place? BR, Erwin RE: Automatic Ethernet connection checking and informing in case of troubles ? - Joep - 06.11.2019 (05.11.2019, 20:21)Erwin van der Zwart Wrote: Hi Joep, welcome at the forum, took you a loooooooong time to join (:Thanks for the welcome Erwin The good thing with my script is that it will send it's complete status after startup so you got all the information you need from the controller. There's also a function to check wether or not there is an network connection so that part can help you detecting the fysical connection. And beside that you could also check the internet connection so your half way.. Only thing is that you can't mail this information any longer if there's no internet connection. But what you could do for example is to check and send an email every night. So when it will not arrive the next morning you know something is wrong. RE: Automatic Ethernet connection checking and informing in case of troubles ? - josemabera - 13.11.2019 Good morning Joep In the script the command to send this information by e-mail would be missing, right? How can I send this information by e-mail every day at night as you comment? (only one e-mail per day, or every week) Thank you very much for sharing your knowledge in the forum Br Josema RE: Automatic Ethernet connection checking and informing in case of troubles ? - Joep - 13.11.2019 (13.11.2019, 05:02)josemabera Wrote: Good morning Joep Hi Josema, Below the complete script to get all the information, write it to the log and send it by email using the default email function. You can use this script as a scheduled script and run it every x days or once a week. What you need to do is to set the correct receiver email address in the last line of the script and if you want you can change the Dutch words to your own language. --status van de homeLYnk ophalen, loggen en mailen require('json') require('socket.http') ip = io.readproc('if-json') ip = json.decode(ip) log("IP adres: " ..ip.eth0.inetaddr) socket.http.timeout = 5 data = socket.http.request('http://ip-api.com/json') if data then data = json.decode(data) log("WAN IP: "..data.query) log("Plaats: "..data.city) log("Provincie: "..data.region) log("Land: "..data.countryCode) log("Latitude: "..data.lat) log("Longitude: "..data.lon) else log("Er is mogelijk geen internetverbinding actief") end log("Naam: " ..socket.dns.gethostname()) io.input("/sys/class/net/eth0/carrier") carrier = io.read("*line") if carrier == "1" then log("Verbonden met het netwerk") else log("Geen verbinding met het netwerk") end io.input("/sys/class/net/eth0/operstate") state = io.read("*line") if state == "up" then log("De netwerkverbinding is actief") else log("De netwerkverbinding is inactief") end log("Directe link pc/tablet visualisering: http://"..socket.dns.gethostname()..".local/scada-vis") log("Directe link smartphone visualisering: http://"..socket.dns.gethostname()..".local/scada-vis/touch") log("Interne link pc/tablet visualisering: http://"..ip.eth0.inetaddr.."/scada-vis") log("Interne link smartphone visualisering: http://"..ip.eth0.inetaddr.."/scada-vis/touch") log("Externe link pc/tablet visualisering: http://"..data.query.."/scada-vis") log("Externe link smartphone visualisering: http://"..data.query.."/scada-vis/touch") subject = "homeLYnk status: "..socket.dns.gethostname().." "..data.city message = "Statusinformatie".."\r\n\r\n".. "IP adres: " ..ip.eth0.inetaddr.."\r\n".. "WAN IP: "..data.query.."\r\n".. "Plaats: "..data.city.."\r\n".. "Provincie: "..data.region.."\r\n".. "Land: "..data.countryCode.."\r\n".. "Latitude: "..data.lat.."\r\n".. "Longitude: "..data.lon.."\r\n".. "Naam: " ..socket.dns.gethostname().."\r\n\r\n".. "Directe link pc/tablet visualisering: http://"..socket.dns.gethostname()..".local/scada-vis".."\r\n".. "Directe link smartphone visualisering: http://"..socket.dns.gethostname()..".local/scada-vis/touch".."\r\n\r\n".. "Interne link pc/tablet visualisering: http://"..ip.eth0.inetaddr.."/scada-vis".."\r\n".. "Interne link smartphone visualisering: http://"..ip.eth0.inetaddr.."/scada-vis/touch".."\r\n\r\n".. "Externe link pc/tablet visualisering: http://"..data.query.."/scada-vis".."\r\n".. "Externe link smartphone visualisering: http://"..data.query.."/scada-vis/touch" mail('your@email.com', subject, message) RE: Automatic Ethernet connection checking and informing in case of troubles ? - josemabera - 14.11.2019 (13.11.2019, 07:58)Joep Wrote:Goedemorgen Joep!(13.11.2019, 05:02)josemabera Wrote: Good morning Joep Ik ben onder de indruk! Het is verbazingwekkend wat je kunt doen met de kennis en controle die je hebt Heel erg bedankt voor je hulp. Ik zal kijken of ik het in werking kan stellen RE: Automatic Ethernet connection checking and informing in case of troubles ? - Dré - 06.03.2022 (13.11.2019, 07:58)Joep Wrote:(13.11.2019, 05:02)josemabera Wrote: Good morning Joep I was trying to use this script, this script is working, i see the results by log, but i got a error on line 65 'mail('your@email.com', subject, message)' I know it is 'mail' but i dont know how to fix this. What script do i need to use it and do i put it on user.libraries? RE: Automatic Ethernet connection checking and informing in case of troubles ? - admin - 07.03.2022 mail() function should be in Common functions. What kind of error are you getting exactly? RE: Automatic Ethernet connection checking and informing in case of troubles ? - Dré - 07.03.2022 (07.03.2022, 07:31)admin Wrote: mail() function should be in Common functions. What kind of error are you getting exactly? At the moment i cant take a look, But it means he cant find the mail template. Because there isnt a script for setting for sending mail. If i look at the log of the LM i see the values, so it is just the mail function what is not working. RE: Automatic Ethernet connection checking and informing in case of troubles ? - admin - 07.03.2022 If you are getting attempt to call global 'mail' (a nil value) then the mail function is missing from common functions. You can add it back manually: Code: -- send an e-mail RE: Automatic Ethernet connection checking and informing in case of troubles ? - Dré - 07.03.2022 Thanks Admin, it is working |