Skip to content

Commit

Permalink
async implementation to flashfloor at the same time.
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdev2 committed Oct 10, 2020
1 parent 9f88d29 commit 611ce92
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 27 deletions.
74 changes: 66 additions & 8 deletions floor_flasher/flashfloor.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import os, requests, sys, json
import argparse
import os, requests, sys, json, argparse

import aiohttp, asyncio

from aiohttp import ClientSession

from fabfile import RPi_IPs

Expand Down Expand Up @@ -33,7 +36,55 @@ def check_all_services(RPi_IPs):
else:
print('failed: ', ips['ip_addr'])


async def fetch(url, session):
async with session.get(url) as response:
response_text = await response.text()
response_status = response.status
return (response_status,response_text)

async def post_firmware(url, session, firmwarepath):
async with session.post(url, data={'file': open(firmwarepath, 'rb')}) as response:
response_text = await response.text()
response_status = response.status
return (response_status,response_text)


async def run(type="check",RPi_IPs=RPi_IPs,firmware=None):
# by default check to disable accidental flash all.
tasks = []
if type=="check":
# Fetch all responses within one Client session,
# keep connection alive for all requests.
async with ClientSession() as session:
for RPI in RPi_IPs:
url = "http://" + RPI['ip_addr']
task =asyncio.ensure_future(fetch(url, session))
tasks.append(task)

responses = await asyncio.gather(*tasks)
# you now have all response bodies in this variable
for i in responses:
print(i[0])

elif type == "flashall":
# flash all concurrently but sending the requests one after the other right after the other
# keep connection alive for all requests.
async with ClientSession() as session:
for RPI in RPi_IPs:
url = "http://" + RPI['ip_addr']
task = asyncio.ensure_future(post_firmware(url, session,firmware))
tasks.append(task)

responses = await asyncio.gather(*tasks)
# you now have all response bodies in this variable
for i in responses:
print(i[0])

if __name__ == '__main__':

print("args")

# args
parser = argparse.ArgumentParser()
parser.add_argument('--firmware-path', type=str)
Expand All @@ -50,22 +101,29 @@ def check_all_services(RPi_IPs):

try:
args = parser.parse_args()
print(args)
except:
print('args provided are wrong')
exit()
#exit()

if args.check:
print('Check all services')
check_all_services(RPi_IPs)
exit()
loop = asyncio.get_event_loop()
future = asyncio.ensure_future(run("check"))
loop.run_until_complete(future)
#exit()

if args.firmware_path is None:
print('Please provide absolute path file name as arg to flash')
exit()
#exit()brew update && brew upgrade && brew install openssl

if args.flash_all:
print('Flashing the whole floor')
flash_coroutine(RPi_IPs, args.firmware_path)
else:
loop = asyncio.get_event_loop()
future = asyncio.ensure_future(run(type="flashall",RPi_IPs=RPi_IPs, firmware=args.firmware_path))
loop.run_until_complete(future)
elif args.strip_id:
print('Flashing node strip_id:', args.strip_id, 'node_id:', args.node_id)
send_flash_req(RPi_IPs[args.strip_id-1]['ip_addr'], args.firmware_path, devices=args.node_id)
else:
print("print arg options")
10 changes: 10 additions & 0 deletions summerschool-api/imureader.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[program:imureader]
directory=/home/dummy/sensorfloor/floor_flasher
command=/home/dummy/.local/bin/fab imuread
process_name=%(program_name)s
user=dummy
autostart=true
autorestart=unexpected
redirect_stderr=false
stdout_logfile=/home/dummy/logs/imureader.log
stderr_logfile=/home/dummy/logs/imureader-err.log
10 changes: 10 additions & 0 deletions summerschool-api/liveframe.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[program:live_frame]
directory=/home/dummy/hackathon-summer-school-2020/api/
command=/usr/bin/python3 /home/dummy/hackathon-summer-school-2020/api/live_frame.py --c 6
process_name=%(program_name)s
user=dummy
autostart=true
autorestart=unexpected
redirect_stderr=false
stdout_logfile=/home/dummy/logs/live_frame.log
stderr_logfile=/home/dummy/logs/live_frame-err.log
10 changes: 10 additions & 0 deletions summerschool-api/redispusher.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[program:redispusher]
directory=/home/dummy/sensorfloor/summerschool-api
command=/usr/bin/python3 /home/dummy/sensorfloor/summerschool-api/redis-pusher.py
process_name=%(program_name)s
user=dummy
autostart=true
autorestart=unexpected
redirect_stderr=false
stdout_logfile=/home/dummy/logs/redispusher.log
stderr_logfile=/home/dummy/logs/redispusher-err.log
10 changes: 10 additions & 0 deletions summerschool-api/summerschool-api.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[program:summerschool-api]
directory=/home/dummy/sensorfloor/summerschool-api
command=/usr/bin/python3 /home/dummy/sensorfloor/summerschool-api/main.py
process_name=%(program_name)s
user=dummy
autostart=true
autorestart=unexpected
redirect_stderr=false
stdout_logfile=/home/dummy/logs/summerschool-api.log
stderr_logfile=/home/dummy/logs/summerschool-api-err.log
38 changes: 19 additions & 19 deletions tryouts/directdrive.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,33 +72,33 @@ def readState(slave):

for sensor in sensor_path:
print (sensor._path)
if sensor._path == '/29.47FC2F000000':
if sensor._path == '/29.00FC2F000000':
# if sensor.type == "DS2408":

# normal operation with Comms On
# sleep(1)

# sensor.out_of_testmode = "0"
# sleep(.1)
# sensor.out_of_testmode = "1"
# sleep(.1)
# sensor.PIO_BYTE = "64"
# sleep(.1)
# sensor.PIO_BYTE = "147"
sensor.out_of_testmode = "0"
sleep(.1)
sensor.out_of_testmode = "1"
sleep(.1)
sensor.PIO_BYTE = "64"
sleep(.1)
sensor.PIO_BYTE = "147"


# # set node bootloader mode
sensor.PIO_BYTE = "159"
sleep(.1) # wait until chip boots to BL mode
sensor.PIO_BYTE = "150"
sleep(.1)
# sensor.PIO_BYTE = "159"
# sleep(.1) # wait until chip boots to BL mode
# sensor.PIO_BYTE = "150"
# sleep(.1)

# Interrupt to read IMU
# while 1:
# sensor.PIO_2 = "1"
# # sleep(1)
# sensor.PIO_2 = "0"
# # sleep(1)
# sensor.PIO_2 = "1"
# sleep(5)
while 1:
sensor.PIO_2 = "1"
# sleep(1)
sensor.PIO_2 = "0"
# sleep(1)
sensor.PIO_2 = "1"
sleep(5)

0 comments on commit 611ce92

Please sign in to comment.