Skip to content
Permalink
Browse files

5.0.3

  • Loading branch information
rpi4
rpi4 committed Mar 18, 2020
1 parent b2db923 commit 104561b7d87ccf20b097647496b3deafca70d1bc
@@ -1,2 +1,2 @@
__pycache__/
*.pyc
__pycache__/
*.pyc
@@ -1,2 +1,2 @@
__pycache__/
*.pyc
__pycache__/
*.pyc
@@ -4,3 +4,4 @@ DIR=$( cd "$( dirname "$0" )" && cd ../../ && pwd )

/bin/bash $DIR/app/scripts/ds2482.sh
/bin/rm $DIR/data/reboot
/bin/rm $DIR/data/nettemp.pid
@@ -25,7 +25,21 @@ def gpio_settings():
except:
pass

if request.form.get('send-gpio-del') == 'yes':
if request.form.get('send-new-dht11') == 'yes':
name = request.form['name']
gpio = request.form['gpio']
try:
os.mkdir("data/sensors/dht11/")
except:
pass
if name.isalnum() and gpio.isalnum():
try:
os.mkdir('data/sensors/dht11/'+name)
Path('data/sensors/dht11/'+name+'/'+gpio).touch()
except:
pass

if request.form.get('send-dht22-del') == 'yes':
name = request.form['name']
gpio = request.form['gpio']
if name.isalnum() and gpio.isalnum():
@@ -35,11 +49,26 @@ def gpio_settings():
except:
pass

data = []
if request.form.get('send-dht11-del') == 'yes':
name = request.form['name']
gpio = request.form['gpio']
if name.isalnum() and gpio.isalnum():
try:
Path('data/sensors/dht11/'+name+'/'+gpio).unlink()
os.rmdir('data/sensors/dht11/'+name)
except:
pass

data22 = []
for name in os.listdir('data/sensors/dht22/'):
for gpio in os.listdir('data/sensors/dht22/'+name):
data.append([name, gpio])
data22.append([name, gpio])

data11 = []
for name in os.listdir('data/sensors/dht11/'):
for gpio in os.listdir('data/sensors/dht11/'+name):
data11.append([name, gpio])

return render_template('devices_gpio.html', data=data)
return render_template('devices_gpio.html', data22=data22, data11=data11)


@@ -11,7 +11,8 @@ def __init__(self, rom, type, value, name):

def request(self):
url = "http://localhost:8080/local"
data = {"rom":self.rom,"type":self.type, "device":"","value":self.value,"name":self.name}
data = [{"rom":self.rom,"type":self.type, "device":"","value":self.value,"name":self.name}]
r = requests.post(url,json=data)
r.close
print("Sensor %s value: %s" % (self.rom, self.value))

@@ -4,6 +4,8 @@
import datetime
from datetime import timedelta
import sys, os
import socket
from subprocess import check_output
dir=(os.path.abspath(os.path.join(os.path.dirname( __file__ ), '..', '..')))
sys.path.append(dir)

@@ -195,6 +197,9 @@ def update_mail(id, action):
conn.close()

if recipients:
hostname = socket.gethostname()
host_ip = check_output(['hostname', '-I']).decode()
print(host_ip)
data=check_mail()
conn = sqlite3.connect(dbf)
conn.row_factory = sqlite3.Row
@@ -224,18 +229,21 @@ def update_mail(id, action):
text = """\
Hi,
{data}
""".format(data=data)
Notification from: https://{host_ip}
""".format(data=data,host_ip=host_ip)
html = """\
<html>
<body>
<p>
{data}<br>
<br >
{data}<br>
<br>
Notification from: <a href="https://{host_ip}">https://{hostname}</a>
<br>
<a href="http://techfreak.pl/tag/nettemp"> <img src="http://techfreak.pl/wp-content/uploads/2012/12/nettemp.pl_.png" style="width:120px;height:40px;"></a><br>
</p>
</body>
</html>
""".format(data=data)
""".format(data=data, hostname=hostname, host_ip=host_ip)

# Turn these into plain/html MIMEText objects
part1 = MIMEText(text, "plain")
@@ -0,0 +1,12 @@
#! /bin/bash

trap 'systemctl start gunicorn.service' EXIT
systemctl stop gunicorn.service
source venv/bin/activate

export PYTHONDONTWRITEBYTECODE=1
export FLASK_APP=nettemp.py
export FLASK_ENV=development
export FLASK_RUN_PORT=8080
export FLASK_RUN_HOST=127.0.0.1
flask run
@@ -27,7 +27,7 @@ def data():
for value, name, rom, type, url, token in data():
rom = rom+'-'+group
name = name+'-'+group
data = {"rom":rom,"type":type,"name":name,"value":value,"group":group}
data = [{"rom":rom,"type":type,"name":name,"value":value,"group":group}]
send(token, data, url)
else:
print("[ nettemp ] nothing to do")
@@ -6,6 +6,7 @@ mkdir -p $dir/data/db
mkdir -p $dir/data/dbf
mkdir -p $dir/data/dba
mkdir -p $dir/data/sensors/dht22/
mkdir -p $dir/data/sensors/dht11/

chown -R root.www-data $dir
chmod -R 770 $dir
@@ -2,7 +2,7 @@
import json
requests.packages.urllib3.disable_warnings()

url = "https://172.18.10.12/register"
url = "https://172.18.10.13/register"

data = {'username':'admin','password':'admin'}
print ("[*] Register and send", (data))
@@ -14,19 +14,13 @@
print (token)

def send(token,data):
url = "https://172.18.10.12/sensor"
url = "https://172.18.10.13/sensor"
r = requests.post(url,headers={'Content-Type':'application/json', 'Authorization': 'Bearer {}'.format(token)},json=data, verify=False)
print (r.content)

data = {"rom":"test_test","type":"temp", "device":"1wire", "ip":"", "gpio":"", "i2c":"", "usb":"","name":"psos","value":"-10"}
data = [{"rom":"test1","type":"temp", "name":"test1","value":"-10"},{"rom":"test2","type":"temp", "name":"test2","value":"-10"}]
#data = [{"rom":"test1","type":"temp", "name":"test1","value":"-10"}]
send(token, data)
print ('[*] Data send with access_token')


#r = requests.post(url,json=data)

#data = {"rom":"press","type":"press","device":"usb", "ip":"", "gpio":"", "i2c":"", "usb":"","name":"press","value":"10"}
#r = requests.post(url,json=data)

#data = {"rom":"humid","type":"humid","device":"usb", "ip":"", "gpio":"", "i2c":"", "usb":"","name":"humid","value":"10"}
#r = requests.post(url,json=data)
@@ -160,70 +160,69 @@ def create_sensor(rom, data, data2, map_settings):
return None

def sensor():
json = request.get_json()

rom = None
if 'rom' in json:
rom=json['rom']

type = None
if 'type' in json:
type=json['type']

device = None
if 'device' in json:
device=json['device']

ip = None
if 'ip' in json:
ip = json['ip']

gpio = None
if 'gpio' in json:
gpio=json['gpio']

i2c = None
if 'i2c' in json:
i2c=json['i2c']

usb = None
if 'usb' in json:
usb=json['usb']

name = randint(1000,9000)
if 'name' in json:
name=json['name']
if not json['name']:
name = randint(1000,9000)

tmp = None
if 'tmp' in json:
tmp=json['tmp']

value = None
if 'value' in json:
value=json['value']
data = request.get_json()
for j in data:
rom = None
if 'rom' in j:
rom=j['rom']
type = None
if 'type' in j:
type=j['type']

device = None
if 'device' in j:
device=j['device']

ip = None
if 'ip' in j:
ip = j['ip']

gpio = None
if 'gpio' in j:
gpio=j['gpio']

i2c = None
if 'i2c' in j:
i2c=j['i2c']

usb = None
if 'usb' in j:
usb=j['usb']

name = randint(1000,9000)
if 'name' in j:
name=j['name']
if not j['name']:
name = randint(1000,9000)

tmp = None
if 'tmp' in j:
tmp=j['tmp']

value = None
if 'value' in j:
value=j['value']

group = type
if 'group' in json:
group=json['group']

map_id = randint(1000,9000)
map_y = randint(50,600)
map_x = randint(50,600)
data = [rom, type, device, ip, gpio, i2c, usb, name]
data2 = [group, map_id, rom]
map_settings = [type, map_y, map_x, 'on', map_id, 'on']
value=check_value(value, type, rom)


if insert_db(rom, value) == False:
new_db(rom)
insert_db(rom,value)

if update_sensor_tmp(rom,value) == False:
create_sensor(rom,data,data2,map_settings)
update_sensor_tmp(rom,value)
group = type
if 'group' in j:
group=j['group']

map_id = randint(1000,9000)
map_y = randint(50,600)
map_x = randint(50,600)
data = [rom, type, device, ip, gpio, i2c, usb, name]
data2 = [group, map_id, rom]
map_settings = [type, map_y, map_x, 'on', map_id, 'on']
value=check_value(value, type, rom)


if insert_db(rom, value) == False:
new_db(rom)
insert_db(rom,value)

if update_sensor_tmp(rom,value) == False:
create_sensor(rom,data,data2,map_settings)
update_sensor_tmp(rom,value)


@app.route('/sensor', methods=['POST'])
@@ -7,29 +7,29 @@
get_group = ''
get_name = ''

def select_sensors(get_type, get_group, get_name):
def select_sensors(get_type, get_group, get_id):
conn = sqlite3.connect(app.db)
c = conn.cursor()
if get_type:
print (get_type)
sql = ''' SELECT sensors.id, sensors.time, sensors.tmp, sensors.name, sensors.rom,
sensors.tmp_min, sensors.tmp_max, sensors.alarm, sensors.type, sensors.charts,
sensors.ch_group, sensors.minmax, sensors.fiveago, sensors.map_id, maps.map_on, sensors.email, sensors.email_delay, sensors.node, sensors.adj FROM sensors INNER JOIN maps ON sensors.map_id = maps.map_id WHERE sensors.type=? '''
sensors.ch_group, sensors.minmax, sensors.fiveago, sensors.map_id, maps.map_on, sensors.email, sensors.email_delay, sensors.node, sensors.adj, sensors.email_status, sensors.ip FROM sensors INNER JOIN maps ON sensors.map_id = maps.map_id WHERE sensors.type=? '''
c.execute(sql, [get_type])
elif get_group:
sql = ''' SELECT sensors.id, sensors.time, sensors.tmp, sensors.name, sensors.rom,
sensors.tmp_min, sensors.tmp_max, sensors.alarm, sensors.type, sensors.charts,
sensors.ch_group, sensors.minmax, sensors.fiveago, sensors.map_id, maps.map_on, sensors.email, sensors.email_delay, sensors.node, sensors.adj FROM sensors INNER JOIN maps ON sensors.map_id = maps.map_id WHERE sensors.ch_group=? '''
sensors.ch_group, sensors.minmax, sensors.fiveago, sensors.map_id, maps.map_on, sensors.email, sensors.email_delay, sensors.node, sensors.adj, sensors.email_status, sensors.ip FROM sensors INNER JOIN maps ON sensors.map_id = maps.map_id WHERE sensors.ch_group=? '''
c.execute(sql, [get_group])
elif get_name:
elif get_id:
sql = ''' SELECT sensors.id, sensors.time, sensors.tmp, sensors.name, sensors.rom,
sensors.tmp_min, sensors.tmp_max, sensors.alarm, sensors.type, sensors.charts,
sensors.ch_group, sensors.minmax, sensors.fiveago, sensors.map_id, maps.map_on, sensors.email, sensors.email_delay, sensors.node, sensors.adj FROM sensors INNER JOIN maps ON sensors.map_id = maps.map_id WHERE sensors.name=? '''
c.execute(sql, [get_name])
sensors.ch_group, sensors.minmax, sensors.fiveago, sensors.map_id, maps.map_on, sensors.email, sensors.email_delay, sensors.node, sensors.adj, sensors.email_status, sensors.ip FROM sensors INNER JOIN maps ON sensors.map_id = maps.map_id WHERE sensors.id=? '''
c.execute(sql, [get_id])
else:
sql = ''' SELECT sensors.id, sensors.time, sensors.tmp, sensors.name, sensors.rom,
sensors.tmp_min, sensors.tmp_max, sensors.alarm, sensors.type, sensors.charts,
sensors.ch_group, sensors.minmax, sensors.fiveago, sensors.map_id, maps.map_on, sensors.email, sensors.email_delay, sensors.node, sensors.adj FROM sensors INNER JOIN maps ON sensors.map_id = maps.map_id ORDER BY ch_group ASC '''
sensors.ch_group, sensors.minmax, sensors.fiveago, sensors.map_id, maps.map_on, sensors.email, sensors.email_delay, sensors.node, sensors.adj, sensors.email_status, sensors.ip FROM sensors INNER JOIN maps ON sensors.map_id = maps.map_id ORDER BY ch_group ASC '''
c.execute(sql)
data = c.fetchall()
conn.close()
@@ -56,7 +56,7 @@ def select_type():
def settings_sensors():
get_type = request.args.get("type")
get_group = request.args.get("group")
get_name = request.args.get("name")
get_id = request.args.get("id")

if request.method == "POST":
if request.form.get('send-node') == 'yes':
@@ -267,6 +267,6 @@ def settings_sensors():


type = select_type()
data = select_sensors(get_type, get_group, get_name)
data = select_sensors(get_type, get_group, get_id)
group = select_group()
return render_template('sensor_settings.html', data=data, group=group, type=type, get_name=get_name, get_group=get_group, get_type=get_type)
return render_template('sensor_settings.html', data=data, group=group, type=type, get_id=get_id, get_group=get_group, get_type=get_type)

0 comments on commit 104561b

Please sign in to comment.
You can’t perform that action at this time.