Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync frontend team with latest from master #222

Merged
merged 80 commits into from Mar 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
80 commits
Select commit Hold shift + click to select a range
8ff6b37
testing nesting the current test scripts in a travis matrix
ab7289 Mar 9, 2020
1d4b173
merged changes from master
ab7289 Mar 13, 2020
fa53935
Merge branch 'travis-test-sync' into travis-test
ab7289 Mar 13, 2020
e380ca6
adding job separator
ab7289 Mar 13, 2020
74aee1c
adding travis defaults to fix build config warnings
ab7289 Mar 13, 2020
a7c7f93
created basic raspbian based Dockerfile and updated the hardware buil…
ab7289 Mar 13, 2020
689e8c9
fixed .travis.yml formatting errors
ab7289 Mar 13, 2020
885afd6
fixed misspelling when preparing qemu
ab7289 Mar 13, 2020
6e3d596
modified the before_script
ab7289 Mar 13, 2020
c0b94fa
added some basic logging statements to see if docker container is sta…
ab7289 Mar 13, 2020
d28654f
updated script to try to get docker image to run
ab7289 Mar 13, 2020
aad23e2
added check to see if container ran the command
ab7289 Mar 13, 2020
762f405
modified the script portion to see if the build will finish successfu…
ab7289 Mar 13, 2020
7892f07
seeing if the -rm flag is the issue
ab7289 Mar 13, 2020
00f6b07
removed docker ps call as it seems like that was keeping the containe…
ab7289 Mar 13, 2020
03de6d8
removed docker info phrase
ab7289 Mar 13, 2020
526f4ac
modified test
ab7289 Mar 13, 2020
940e37a
removed extraneous test steps
ab7289 Mar 13, 2020
b4cf91c
added some comments and cleaned up spacing
ab7289 Mar 13, 2020
cbb2f9f
updated Dockerfile to use a more up to date base image
ab7289 Mar 14, 2020
8e0ff17
installed raspi-config dependency
ab7289 Mar 14, 2020
f92f350
added run script
ab7289 Mar 14, 2020
8969f04
Added environment var file
PrabhanshuAttri Mar 15, 2020
e828933
Added logger module
PrabhanshuAttri Mar 15, 2020
2389f02
Added utils
PrabhanshuAttri Mar 15, 2020
97b33d7
Using logger in serial write
PrabhanshuAttri Mar 15, 2020
e7f30b4
clean up
PrabhanshuAttri Mar 15, 2020
20b33e7
Added logger to serial read
PrabhanshuAttri Mar 15, 2020
722bc4f
Fixed code formatting issues
PrabhanshuAttri Mar 15, 2020
82d62da
Fixed env var name
PrabhanshuAttri Mar 15, 2020
f2ebb60
fixed serial read logging
PrabhanshuAttri Mar 15, 2020
22e30e9
clean up
PrabhanshuAttri Mar 15, 2020
7884e75
replaced print with logging
PrabhanshuAttri Mar 15, 2020
c013270
Fixed code formatting issues
PrabhanshuAttri Mar 15, 2020
bcc54b1
Added README instructions
PrabhanshuAttri Mar 15, 2020
2e368ed
Merge pull request #125 from gcivil-nyu-org/travis-test
ab7289 Mar 15, 2020
bd26feb
merged master and resolved conflicts
ab7289 Mar 15, 2020
3935611
updated travis
ab7289 Mar 15, 2020
e3fc25e
Merge pull request #136 from gcivil-nyu-org/feat/logger-env
PrabhanshuAttri Mar 16, 2020
a78be70
Merge pull request #138 from gcivil-nyu-org/sync-master
PrabhanshuAttri Mar 16, 2020
5055604
Added lan_client
PrabhanshuAttri Mar 18, 2020
a5c99e3
Renamed and fixed minor issue
PrabhanshuAttri Mar 18, 2020
9495901
Renamed lan server
PrabhanshuAttri Mar 18, 2020
ed7f440
updated logging
PrabhanshuAttri Mar 18, 2020
179e7a4
minor fix
PrabhanshuAttri Mar 18, 2020
8b5e623
added logging in file
PrabhanshuAttri Mar 18, 2020
64a1b14
Added more info to README
PrabhanshuAttri Mar 18, 2020
5055402
Added lan server port to env
PrabhanshuAttri Mar 18, 2020
7f5f5e3
Merge pull request #140 from gcivil-nyu-org/hardware-team
MichaelLally Mar 18, 2020
32baa01
added .coveragerc file to control pythong coverage, added initial tests
ab7289 Mar 18, 2020
3589751
added .coveragerc file to control coverage
ab7289 Mar 18, 2020
8f4428e
fixed black violation
ab7289 Mar 18, 2020
b0ba5a8
removed .coveragerc as we need different run parameters depending on …
ab7289 Mar 18, 2020
ee4a3fe
Merge pull request #146 from gcivil-nyu-org/feat/logger-env
PrabhanshuAttri Mar 19, 2020
d22ea21
modified Dockerfile and travis build
ab7289 Mar 19, 2020
4771dbd
Merge remote-tracking branch 'origin/hardware-team' into feature/hard…
ab7289 Mar 19, 2020
260532a
reverted coveragerc deletion
ab7289 Mar 19, 2020
849f146
Merge branch 'test-revert' into feature/hardware-tests
ab7289 Mar 19, 2020
c6f3f8c
added tests for CommunicationsPi.is_serial_usb
ab7289 Mar 19, 2020
c6754f4
modified travis config to utilize config files instead of passing in …
ab7289 Mar 19, 2020
48cd564
updated check.sh since we no longer need to pass in flags
ab7289 Mar 19, 2020
dccc0bf
added tests for extra_info and get_port in CommunicationsPi
ab7289 Mar 19, 2020
2fa674c
fixed black violations
ab7289 Mar 19, 2020
c584cce
Merge branch 'lint-config' into feature/hardware-tests
ab7289 Mar 20, 2020
5bc9027
fixed flake8 violations
ab7289 Mar 20, 2020
ce23b28
fixed black violations
ab7289 Mar 20, 2020
3d0c138
clean up
PrabhanshuAttri Mar 20, 2020
ce86d5a
Merge remote-tracking branch 'origin/feature/hardware-tests' into fea…
ab7289 Mar 20, 2020
fe32cf5
added explanatory comments
ab7289 Mar 20, 2020
9700f88
updated test-requirements.txt to add testfixtures module and added so…
ab7289 Mar 21, 2020
cf02f26
fixed black violations
ab7289 Mar 21, 2020
2b1b8c8
added basic tests for logger public methods and removed debug print s…
ab7289 Mar 21, 2020
da21fd9
updated flake8 line length to the django-recommended 119
ab7289 Mar 21, 2020
15acf81
added CommunicationsPi.utils tests and fixed a line in utils
ab7289 Mar 21, 2020
5b12f0b
commented out lines not in use
ab7289 Mar 21, 2020
f87078f
Merge pull request #149 from gcivil-nyu-org/feature/hardware-tests
PrabhanshuAttri Mar 23, 2020
b61f6d8
Merge pull request #155 from gcivil-nyu-org/sync-master-hardware
PrabhanshuAttri Mar 24, 2020
432dfd1
Merge pull request #154 from gcivil-nyu-org/hardware-team
ab7289 Mar 26, 2020
0acf88a
Get grafana in sync with master, preparing to merge frontend to master.
daisycrego Mar 27, 2020
81bb7a2
Merge branch 'frontend-team' into grafana
daisycrego Mar 27, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 14 additions & 0 deletions .coveragerc
@@ -0,0 +1,14 @@
# .coveragerc to control coverage.py
[run]
omit =
*/site-packages/*
*/distutils/*
*/tests/*
hardware/setup/*
source =
mysite
mercury
hardware
ag_data
hardware/CommunicationsPi
hardware/SensorPi
2 changes: 1 addition & 1 deletion .flake8
@@ -1,5 +1,5 @@
[flake8]
max-line-length = 92
max-line-length = 119
exclude =
.git,
__pycache__,
Expand Down
86 changes: 56 additions & 30 deletions .travis.yml
@@ -1,40 +1,66 @@
language: python
dist: xenial
os: linux
language: ruby

python:
- '3.6'
jobs:
include:
# run django tests
- language: python

addons:
firefox: latest
python: '3.6'

dist: xenial
services:
- xvfb
addons:
firefox: latest

dist: xenial
services:
- xvfb
- postgresql

services:
- postgresql
before_install:
- wget https://github.com/mozilla/geckodriver/releases/download/v0.26.0/geckodriver-v0.26.0-linux64.tar.gz
- mkdir geckodriver
- tar -xzf geckodriver-v0.26.0-linux64.tar.gz -C geckodriver
- export PATH=$PATH:$PWD/geckodriver

before_install:
- wget https://github.com/mozilla/geckodriver/releases/download/v0.26.0/geckodriver-v0.26.0-linux64.tar.gz
- mkdir geckodriver
- tar -xzf geckodriver-v0.26.0-linux64.tar.gz -C geckodriver
- export PATH=$PATH:$PWD/geckodriver
install:
- pip install --upgrade pip
- pip install -r requirements.txt
- pip install -r test-requirements.txt

install:
- pip install --upgrade pip
- pip install -r requirements.txt
- pip install -r test-requirements.txt
before_script:
- psql -c 'create database mercury;' -U postgres
- python manage.py migrate
- python manage.py collectstatic --noinput

before_script:
- psql -c 'create database mercury;' -U postgres
- python manage.py migrate
- python manage.py collectstatic --noinput
script:
- black --check --diff .
# modify .flake8 env file to update flake8 configuration
- flake8 .
# modify .coveragerc env file to update test configuration
- coverage run manage.py test

script:
- black --check --exclude "migrations/" mysite mercury ag_data
- flake8 mysite/ mercury/ ag_data/
- coverage run --source=mysite,mercury,ag_data --omit="migrations/*" manage.py test
after_script:
- coveralls
- cat geckodriver.log

after_script:
- coveralls
- cat geckodriver.log
# run the hardware tests
- language: bash

# python: '3.6'

services:
- docker

before_script:
# prepare qemu for arm emulation on x64 hardware
- docker run --rm --privileged multiarch/qemu-user-static:register --reset
# build image
- docker build -t gcivil-nyu-org/spring2020-cs-gy-9223-class .

script:
# basic help world test to see if it's working
- docker run gcivil-nyu-org/spring2020-cs-gy-9223-class grep -q "Hello, Docker!" hello.txt
# - black --check --exclude "migrations/" hardware


13 changes: 13 additions & 0 deletions Dockerfile
@@ -0,0 +1,13 @@
FROM raspbian/stretch

# install common build dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
raspi-config

# copy setup scripts
COPY ./hardware .

# run setup
RUN bash ./setup/raspberrypi-common.sh

RUN echo "Hello, Docker!" > hello.txt
17 changes: 17 additions & 0 deletions hardware/CommunicationsPi/README.md
@@ -0,0 +1,17 @@
# CommunicationsPi

### This directory contains all the scripts related to communications via LAN, Radio and internet.

Note: `env` file contains environment variables required to run different services. Please run the following command to
export variables before running any service.

```
cd hardware
if [ -f env ]; then export $(cat env | sed 's/#.*//g' | xargs); fi
```

##### Scripts
- `lan_client.py`: Sends post data via LAN to Local LAN server
- `lan_server.py`: Listens to LAN clients
- `serial_write.py`: Sends data via radio serial
- `serial_read.py`: Listens to radio serial
Empty file.
42 changes: 21 additions & 21 deletions hardware/CommunicationsPi/find_port.py
Expand Up @@ -6,45 +6,45 @@


def is_usb_serial(port, args):
if port.vid is None:
if port["vid"] is None:
return False
if not args.vid is None:
if port.vid != args.vid:
if not args.get("vid") is None:
if port["vid"] != args.get("vid"):
return False
if not args.pid is None:
if port.pid != args.pid:
if not args.get("pid") is None:
if port.get("pid") != args.get("pid"):
return False
if not args.vendor is None:
if not port.manufacturer.startswith(args.vendor):
if not args.get("vendor") is None:
if not port["manufacturer"].startswith(args.get("vendor")):
return False
if not args.serial is None:
if not port.serial_number.startswith(args.serial):
if not args.get("serial") is None:
if not port["serial_number"].startswith(args.get("serial")):
return False
if not args.intf is None:
if port.interface is None or not args.intf in port.interface:
if not args.get("intf") is None:
if port["interface"] is None or not args.get("intf") in port.get("interface"):
return False
return True


def extra_info(port):
extra_items = []
if port.manufacturer:
extra_items.append("vendor '{}'".format(port.manufacturer))
if port.serial_number:
extra_items.append("serial '{}'".format(port.serial_number))
if port.interface:
extra_items.append("intf '{}'".format(port.interface))
if port.get("manufacturer"):
extra_items.append("vendor '{}'".format(port["manufacturer"]))
if port.get("serial_number"):
extra_items.append("serial '{}'".format(port["serial_number"]))
if port.get("interface"):
extra_items.append("intf '{}'".format(port["interface"]))
if extra_items:
return " with " + " ".join(extra_items)
return ""


def getPort():
def get_port():
for port in serial.tools.list_ports.comports():
if is_usb_serial(port, None):
if is_usb_serial(port, {}):
print(port)
print(port.device)
return
print(port["device"])
return "port found"
return


Expand Down
24 changes: 24 additions & 0 deletions hardware/CommunicationsPi/lan_client.py
@@ -0,0 +1,24 @@
import os
import time
import json
import requests
from requests.exceptions import HTTPError
from utils import get_logger

logging = get_logger("LAN_CLIENT_LOG_FILE")

url = os.environ["LAN_SERVER"]

logging.info("Pinging")
while True:
try:
payload = {"key1": "value1", "key2": "value2"}
logging.info("data: " + json.dumps(payload))
response = requests.post(url, data=payload)
response.raise_for_status()
except HTTPError as http_err:
logging.error("HTTP error occurred: {}".format(str(http_err)))
except Exception as err:
logging.error("error occurred: {}".format(str(err)))
else:
time.sleep(1)
@@ -1,11 +1,11 @@
#!/usr/bin/env python3
"""
Very simple HTTP server in python for logging requests
Usage::
./server.py [<port>]
"""

from http.server import BaseHTTPRequestHandler, HTTPServer
import logging
from utils import get_logger

# Logs status in a file
log = get_logger("LAN_SERVER_LOG_FILE")


class S(BaseHTTPRequestHandler):
Expand All @@ -32,6 +32,7 @@ def do_POST(self):
str(self.headers),
post_data.decode("utf-8"),
)
log.info("data: " + str(post_data))

self._set_response()
self.wfile.write("POST request for {}".format(self.path).encode("utf-8"))
Expand Down
51 changes: 51 additions & 0 deletions hardware/CommunicationsPi/logger.py
@@ -0,0 +1,51 @@
# import sys
import os
import logging

from logging import INFO


class Logger(object):
def __init__(
self,
name,
filename,
format="%(asctime)s | %(levelname)s | %(message)s",
level=INFO,
):
# Initial construct.
self.format = format
self.level = level
self.name = name

# Logger configuration.
self.console_formatter = logging.Formatter(self.format)
self.console_logger = logging.FileHandler(self.get_logger_file(filename), "w")
self.console_logger.setFormatter(self.console_formatter)

# Complete logging config.
self.logger = logging.getLogger(name)
self.logger.setLevel(self.level)
self.logger.addHandler(self.console_logger)

def get_logger_file(self, file_name):
d = os.environ["LOG_DIRECTORY"]
if not os.path.exists(d):
os.makedirs(d)
return d + "/" + file_name

def info(self, msg, extra=None):
print(msg)
self.logger.info(msg, extra=extra)

def error(self, msg, extra=None):
print(msg)
self.logger.error(msg, extra=extra)

def debug(self, msg, extra=None):
print(msg)
self.logger.debug(msg, extra=extra)

def warn(self, msg, extra=None):
print(msg)
self.logger.warn(msg, extra=extra)
2 changes: 1 addition & 1 deletion hardware/CommunicationsPi/main.py
@@ -1 +1 @@
print("Hello Comms")
# print("Hello Comms")
37 changes: 0 additions & 37 deletions hardware/CommunicationsPi/port.py
Expand Up @@ -4,10 +4,8 @@
import glob
import sys
import json

import serial
import serial_asyncio
from django.utils import dateparse


class AsyncSerialProtocol(asyncio.Protocol):
Expand All @@ -27,54 +25,19 @@ def data_received(self, data):
except json.JSONDecodeError:
print()

# print(repr(data))
# json_to_models(repr(data))
# if len(repr(data).split(";")) > 2:
self.transport.close()

def connection_lost(self, exc):
print("port closed")
asyncio.get_event_loop().stop()


def json_to_models(json_str, event_id):
"""
Json example:
{
sensors:{
ss_id : “Sensor id”,
ss_value : {
/*as many values as you wish*/
value_a_name : “value_a”,
value_b_name : “value_b”,
value_c_name : “value_c”
}
date : “2014-03-12T13:37:27+00:00” /*ISO 8601 dates*/
};
"""
res = []
sensors = json_str["sensors"]
ss_id = int(sensors["ss_id"])
ss_value = sensors["ss_value"]
date = dateparse.parse_datetime(sensors["date"])


ser = serial.Serial()
ports = glob.glob("/dev/tty.u*")
print(ports[0])
ser.port = ports[0]
ser.timeout = 1
ser.open()
# print(ser.port)
# print(ser.baudrate)
# print(ser.parity)
# print(ser.stopbits)
# print(ser.bytesize)
# print(ser.timeout)
# while 1:
# x = ser.readline()
# if x is not "":
# print(x)

loop = asyncio.new_event_loop()
coro = serial_asyncio.create_serial_connection(loop, AsyncSerialProtocol, ports[0])
Expand Down