Skip to content

Commit 66f6a8a

Browse files
committed
Try another way
1 parent f8d3f4d commit 66f6a8a

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

WeatherStationCoreLink/Dockerfile.template

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ RUN pip3 install -U setuptools
2424
RUN pip3 install cffi
2525
RUN pip3 install cairocffi==0.6
2626
RUN pip3 install pyserial pusher
27+
RUN pip3 install balena-sdk
2728
#pip also install - git+https://github.com/resin-io/resin-sdk-python.git
2829

2930
# Set our working directory

WeatherStationCoreLink/main.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import json #To parse response
1010
import sqlite3 #Database
1111
import pusher #Pusher.com
12+
from balena import Balena #rebooting
13+
balena = Balena()
1214

1315
os.environ['TZ'] = 'Europe/London' #SetTimezone
1416
def log(message):
@@ -22,17 +24,17 @@ def log(message):
2224
def reboot():
2325
#Use Resin.io api to reboot
2426
log("Rebooting")
25-
rebooturl = str(os.environ.get('BALENA_SUPERVISOR_ADDRESS')) + '/v1/reboot?apikey=' + str(os.environ.get('BALENA_SUPERVISOR_API_KEY'))
26-
result = subprocess.check_output('curl -X POST --header "Content-Type:application/json" "' + rebooturl + '"', shell=True)
27-
log(result)
28-
#time.sleep(60) #Just in case that api call fails as it sometimes does
29-
#os.system('curl -X POST --header "Content-Type:application/json" "' + rebooturl + '"')
30-
#time.sleep(60) # Just in case that api call fails AGAIN as it sometimes does
31-
#reboot()
27+
rebootResult = balena.models.supervisor.reboot()
28+
log(rebootResult)
29+
if rebootResult['DATA'] != 'OK':
30+
log("Reboot Failed")
31+
else:
32+
log("Reboot worked")
33+
time.sleep(43200)
3234
return False #basically put itself into a loop
33-
time.sleep(300)
34-
reboot()
3535

36+
time.sleep(120)
37+
reboot()
3638

3739
serialport = "/dev/ttyUSB0"
3840
baudrate = os.environ.get('baudRate', 19200) #Set the Baudrate to 19200 which is a nice default for the davis logger

0 commit comments

Comments
 (0)