Initial commit
This commit is contained in:
commit
5590713619
2
.gitattributes
vendored
Normal file
2
.gitattributes
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
# Auto detect text files and perform LF normalization
|
||||
* text=auto
|
4
Documentation/Daemon.txt
Normal file
4
Documentation/Daemon.txt
Normal file
@ -0,0 +1,4 @@
|
||||
Files locations :
|
||||
LaunchDaemon file : com.fup.anemometre_daemon.plist - location : /Library/LaunchDaemons/
|
||||
Daemon files location : /usr/local/com.fup.anemometre_daemon/
|
||||
Daemon log files : /var/log/com.fup.anemometre_daemon.log
|
6
anemometer.json
Normal file
6
anemometer.json
Normal file
@ -0,0 +1,6 @@
|
||||
{
|
||||
"sensor": "anemometer",
|
||||
"time": 1351824120,
|
||||
"speed": 27.10,
|
||||
"error": false
|
||||
}
|
30
com.fup.anemometre_daemon.plist
Normal file
30
com.fup.anemometre_daemon.plist
Normal file
@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>Label</key>
|
||||
<string>com.fup.anemometre_daemon</string>
|
||||
<key>ProgramArguments</key>
|
||||
<array>
|
||||
<string>/usr/local/com.fup.anemometre_daemon/start_daemon.sh</string>
|
||||
</array>
|
||||
<key>KeepAlive</key>
|
||||
<true/>
|
||||
<key>StandardOutPath</key>
|
||||
<string>/var/log/com.fup.anemometre_daemon.log</string>
|
||||
<key>StandardErrorPath</key>
|
||||
<string>/var/log/com.fup.anemometre_daemon.log</string>
|
||||
<key>Debug</key>
|
||||
<true/>
|
||||
<key>SoftResourceLimits</key>
|
||||
<dict>
|
||||
<key>Core</key>
|
||||
<integer>9223372036854775807</integer>
|
||||
</dict>
|
||||
<key>HardResourceLimits</key>
|
||||
<dict>
|
||||
<key>Core</key>
|
||||
<integer>9223372036854775807</integer>
|
||||
</dict>
|
||||
</dict>
|
||||
</plist>
|
68
fup_anemo_daemon.log
Normal file
68
fup_anemo_daemon.log
Normal file
@ -0,0 +1,68 @@
|
||||
2024-06-11 23:54:51,982 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-11 23:54:56,988 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-11 23:55:01,994 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-11 23:55:07,001 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-11 23:55:12,008 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-11 23:55:17,014 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-11 23:55:22,021 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-11 23:55:27,028 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-11 23:55:32,031 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-11 23:55:37,035 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-11 23:55:42,042 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-11 23:55:47,048 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-11 23:55:52,053 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-11 23:55:57,058 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-11 23:56:02,063 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-11 23:56:07,068 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-11 23:56:12,076 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-11 23:56:17,083 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-11 23:56:22,089 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:03:17,954 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:03:22,956 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:03:27,962 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:03:32,967 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:03:37,973 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:03:42,979 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:03:47,985 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:03:52,992 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:03:57,998 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:04:03,004 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:04:08,008 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:04:13,013 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:04:18,018 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:04:23,023 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:04:28,027 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:04:33,033 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:04:38,038 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:04:43,043 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:04:48,047 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:04:53,052 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:04:58,057 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:05:03,063 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:05:08,069 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:05:13,075 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:05:18,080 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:05:23,087 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:05:28,091 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:05:33,097 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:05:38,104 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:05:43,111 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:05:48,116 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:05:53,121 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:05:58,127 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:06:03,133 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:06:08,139 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:06:13,145 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:06:18,151 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:06:23,157 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:06:28,162 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:06:33,168 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:09:05,006 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:09:10,011 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:09:15,017 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:09:20,024 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:09:25,030 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:09:30,036 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:09:35,043 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:09:40,049 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:09:45,055 - fup_anemo_daemon - INFO - 27.1
|
133
fup_anemometre_daemon.py
Normal file
133
fup_anemometre_daemon.py
Normal file
@ -0,0 +1,133 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
OSC/Random Example: send random numbers to OSC.
|
||||
|
||||
This example sends a pseudo-random number between 0 and 1024
|
||||
to the OSC receiver on UDP port 2222.
|
||||
"""
|
||||
from pythonosc import udp_client
|
||||
from pythonosc import osc_message_builder
|
||||
import time
|
||||
import signal
|
||||
import random
|
||||
import sys
|
||||
import os
|
||||
import time
|
||||
import argparse
|
||||
import logging
|
||||
import daemon
|
||||
from daemon import pidfile
|
||||
|
||||
# import urllib library
|
||||
from urllib.request import urlopen
|
||||
|
||||
# import json
|
||||
import json
|
||||
|
||||
debug_p = False
|
||||
|
||||
debug_flag = True
|
||||
debug_working_directory = os.path.dirname(os.path.realpath(__file__))
|
||||
|
||||
prod_flag = False
|
||||
prod_working_directory = "/usr/local/com.fup.anemometre_daemon"
|
||||
|
||||
# SIGINT, SIGKILL, SIGTERM, SIGTSTP
|
||||
|
||||
def rcv_SIGNAL(signum, frame, logf):
|
||||
print(signum)
|
||||
|
||||
def check_anemometer(logf, inf):
|
||||
### This does the "work" of the daemon
|
||||
|
||||
logger = logging.getLogger('fup_anemo_daemon')
|
||||
logger.setLevel(logging.INFO)
|
||||
|
||||
fh = logging.FileHandler(logf)
|
||||
fh.setLevel(logging.INFO)
|
||||
|
||||
formatstr = '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
|
||||
formatter = logging.Formatter(formatstr)
|
||||
|
||||
fh.setFormatter(formatter)
|
||||
|
||||
logger.addHandler(fh)
|
||||
|
||||
oscSender = udp_client.UDPClient("localhost", 2222)
|
||||
|
||||
# store the URL in url as
|
||||
# parameter for urlopen
|
||||
url = inf
|
||||
|
||||
while True:
|
||||
# logger.debug("this is a DEBUG message")
|
||||
# logger.info("this is an INFO message")
|
||||
# logger.error("this is an ERROR message")
|
||||
|
||||
# store the response of URL
|
||||
response = urlopen(url)
|
||||
# storing the JSON response
|
||||
# from url in data
|
||||
data_json = json.loads(response.read())
|
||||
|
||||
# print the json response
|
||||
# print(data_json)
|
||||
wind_speed = float(data_json["speed"])
|
||||
logger.info(wind_speed)
|
||||
|
||||
msg = osc_message_builder.OscMessageBuilder(address = "/env_sensors/anemometer")
|
||||
msg.add_arg(wind_speed)
|
||||
oscSender.send(msg.build())
|
||||
|
||||
time.sleep(5)
|
||||
|
||||
def start_daemon(pidf, logf, inf):
|
||||
### This launches the daemon in its context
|
||||
|
||||
global debug_p
|
||||
|
||||
if debug_p:
|
||||
print("fup_anemo_daemon: entered run()")
|
||||
print("fup_anemo_daemon: pidf = {} logf = {}".format(pidf, logf, inf))
|
||||
print("fup_anemo_daemon: about to start daemonization")
|
||||
|
||||
if debug_flag:
|
||||
### XXX pidfile is a context
|
||||
with daemon.DaemonContext(
|
||||
#working_directory='/var/lib/fup_anemo_daemon',
|
||||
working_directory=debug_working_directory,
|
||||
umask=0o002,
|
||||
pidfile=pidfile.TimeoutPIDLockFile(pidf),
|
||||
# SIGINT, SIGKILL, SIGTERM, SIGTSTP
|
||||
signal_map={
|
||||
signal.SIGTERM: rcv_SIGNAL,
|
||||
signal.SIGTSTP: rcv_SIGNAL
|
||||
}
|
||||
) as context:
|
||||
check_anemometer(logf, inf)
|
||||
|
||||
if prod_flag:
|
||||
with daemon.DaemonContext(
|
||||
#working_directory='/var/lib/fup_anemo_daemon',
|
||||
working_directory=prod_working_directory,
|
||||
umask=0o002,
|
||||
pidfile=pidfile.TimeoutPIDLockFile(pidf)#,
|
||||
# SIGINT, SIGKILL, SIGTERM, SIGTSTP
|
||||
# signal_map={
|
||||
# signal.SIGTERM: rcv_SIGNAL,
|
||||
# signal.SIGTSTP: rcv_SIGNAL,
|
||||
# signal.SIGINT: rcv_SIGNAL,
|
||||
# signal.SIGKILL: rcv_SIGNAL
|
||||
# }
|
||||
) as context:
|
||||
check_anemometer(logf, inf)
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser(description="Example daemon in Python")
|
||||
parser.add_argument('-p', '--pid-file', default='fup_anemo_daemon.pid')
|
||||
parser.add_argument('-l', '--log-file', default='fup_anemo_daemon.log')
|
||||
parser.add_argument('-i', '--input-file', default='http://localhost/anemometer.json')
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
start_daemon(pidf=args.pid_file, logf=args.log_file, inf=args.input_file)
|
3
start_daemon.sh
Executable file
3
start_daemon.sh
Executable file
@ -0,0 +1,3 @@
|
||||
#!/bin/sh
|
||||
source /usr/local/com.fup.anemometre_daemon/.venv/bin/activate
|
||||
python /usr/local/com.fup.anemometre_daemon/fup_anemometre_daemon.py
|
Loading…
Reference in New Issue
Block a user