Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
2b9c41d
Create task.md
loerac Aug 25, 2020
1ea17d5
Added post request to feed cat now
Aug 25, 2020
4869e45
Added task TID #009 to update REST API
loerac Aug 25, 2020
59c8526
Remove myself from TID #009
loerac Aug 25, 2020
3f95211
Updated function name to match API call
Aug 25, 2020
357fa07
Updated description to say 'return' instead of 'recieve'
Aug 25, 2020
6ea66aa
Added new TID for app
loerac Aug 25, 2020
5f2105b
Added new TID 011
loerac Aug 27, 2020
889ec74
Merge pull request #2 from loerac/TID002-add-feed-url
loerac Aug 29, 2020
9170806
Use TLS for dataplicity
loerac Aug 29, 2020
e1ddc91
Use TLS for requests
loerac Aug 29, 2020
719b709
Use dataplicity wormhole on port 80
loerac Aug 29, 2020
f3fc8cd
Spelled TLS incorrectly...
loerac Aug 29, 2020
fd168eb
Remove cache
loerac Aug 29, 2020
970da20
Create task.md
loerac Aug 25, 2020
7b6db03
Added post request to feed cat now
Aug 25, 2020
fc1fb18
Added task TID #009 to update REST API
loerac Aug 25, 2020
7dc5434
Remove myself from TID #009
loerac Aug 25, 2020
c751f6b
Updated function name to match API call
Aug 25, 2020
66e0a7d
Updated description to say 'return' instead of 'recieve'
Aug 25, 2020
9e2eaae
Added new TID for app
loerac Aug 25, 2020
5e3dd99
Added new TID 011
loerac Aug 27, 2020
1f7437c
Use TLS for dataplicity
loerac Aug 29, 2020
dc1a501
Resolve conflicts after rebase of TID011-common-libs
loerac Aug 29, 2020
37e89e4
Use dataplicity wormhole on port 80
loerac Aug 29, 2020
4acc4ff
Spelled TLS incorrectly...
loerac Aug 29, 2020
378d251
Remove cache
loerac Aug 29, 2020
432beeb
Resolve conflicts after rebase of TID011-common-libs
loerac Aug 29, 2020
805c672
FQDN and port updates
loerac Aug 29, 2020
edc41dc
Use the FQDN to send data to raspberry pi
loerac Aug 29, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions catfeeder-app/TLSAdapter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import ssl
import sys
import requests
from requests.adapters import HTTPAdapter
from requests.packages.urllib3.poolmanager import PoolManager

class Tls12HttpAdapter(HTTPAdapter):
def init_poolmanager(self, connections, maxsize, block=False):
self.poolmanager = PoolManager(
num_pools=connections, maxsize=maxsize,
block=block, ssl_version=ssl.PROTOCOL_TLSv1_2)
6 changes: 6 additions & 0 deletions catfeeder-app/commonLibs.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,9 @@ def __init__(self):
###
def GetLogFilepath(self):
return self.common_names['log_filepath']

###
# @brief: Return the path for the logfile
###
def GetFQDN(self):
return self.common_names['FQDN']
Binary file not shown.
Binary file not shown.
Binary file not shown.
16 changes: 10 additions & 6 deletions catfeeder-app/src/catfeeder/app.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
"""
An app to feed the cats
"""
import commonLibs
import json
import requests
import toga
import utils
import TLSAdapter
from toga.style import Pack
from toga.style.pack import COLUMN, ROW

BASE_URL = "http://localhost:6969"
BASE_URL = commonLibs.CommonLibs().GetFQDN()
CREATE_TIME = BASE_URL + "/feedingTime"
RECIEVE_A_TIME = BASE_URL + "/feedingTime"
RECIEVE_ALL_TIMES = BASE_URL + "/feedingTimes"

feeding_times = []
logger = utils.Applogger('cat-app')
cat_session = requests.Session()
cat_session.mount(BASE_URL, TLSAdapter.Tls12HttpAdapter())

class CatFeeder(toga.App):
# TODO: Come up with better variable names
Expand Down Expand Up @@ -113,7 +117,7 @@ def sendFeedingTime(self, widget):
send_feeding_times.append(data)

try:
req = requests.post(
req = cat_session.post(
url = CREATE_TIME,
data = str(json.dumps(send_feeding_times))
)
Expand All @@ -131,10 +135,10 @@ def sendFeedingTime(self, widget):
###
def getFeedingTimes(self, widget):
try:
req = requests.get(url = RECIEVE_ALL_TIMES)
if req == None:
logger.error("Uh oh! Received invalid feeding times: Feeding-Time(" + req + ")")
self.error_label.text = "Received invalid feeding times:", req
req = cat_session.get(url = RECIEVE_ALL_TIMES)
if req.json() is None:
logger.error("Uh oh! Received invalid feeding times: Feeding-Time(" + str(req) + ")")
self.error_label.text = "Received invalid feeding times:", str(req)
return
if req.status_code != 200:
logger.error("Uh oh! Request unsuccessful: HTTP(" + str(req.status_code) + ")")
Expand Down
20 changes: 20 additions & 0 deletions catfeeder-machine/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (

type CommonNames struct {
Common_Names string `json:"log_filepath"`
FQDN string `json:"FQDN"`
PORT string `json:"PORT"`
}

var common_names CommonNames
Expand Down Expand Up @@ -39,3 +41,21 @@ func InitCommon() error {
func GetLogFilepath() string {
return common_names.Common_Names
}

/***
* @brief: Return the Fully Qualified Domain Name
*
* @return: See @brief
***/
func GetFQDN() string {
return common_names.FQDN
}

/***
* @brief: Return the port that the server is listening on
*
* @return: See @brief
***/
func GetPORT() string {
return common_names.PORT
}
22 changes: 17 additions & 5 deletions catfeeder-machine/rest-api.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,15 @@ func CreateNewFeedTime(w http.ResponseWriter, r *http.Request) {
rest_log.Println("Received feeding times:" + FeedingTimeStr(ft))
}

/***
* @brief: Handle to feed the cat.
***/
func CreateFeedNow(w http.ResponseWriter, r *http.Request) {
fmt.Println("Place holder to feed cat now, will update once TID003 is complete")
}

/**
* @brief: Handle for recieving a specific feeding time.
* @brief: Handle for returning a specific feeding time.
**/
func ReturnSingleFeedingTime(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
Expand All @@ -59,7 +66,7 @@ func ReturnSingleFeedingTime(w http.ResponseWriter, r *http.Request) {
}

/**
* @brief: Handle for recieving all the feeding times.
* @brief: Handle for returning all the feeding times.
**/
func ReturnAllFeedingTimes(w http.ResponseWriter, r *http.Request) {
mut.Lock()
Expand All @@ -69,12 +76,13 @@ func ReturnAllFeedingTimes(w http.ResponseWriter, r *http.Request) {
}

/**
* @brief: Handle to recieving info on REST API.
* @brief: Handle to returning info on REST API.
**/
func HomePage(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, "Cat Feeding times")
fmt.Fprintln(w, "-----------------------")
fmt.Fprintln(w, "Create new feeding times with '/feedingTime'")
fmt.Fprintln(w, "Create request to feed cat now with '/feedNow'")
fmt.Fprintln(w, "Return all feeding time with '/feedingTimes'")
fmt.Fprintln(w, "Return single feeding time with '/feedingTime/<ID>'")
}
Expand All @@ -88,9 +96,13 @@ func HandleRequests() {
myRouter := mux.NewRouter().StrictSlash(true)
myRouter.HandleFunc("/", HomePage)
myRouter.HandleFunc("/feedingTime", CreateNewFeedTime).Methods("POST")
myRouter.HandleFunc("/feedNow", CreateFeedNow).Methods("POST")
myRouter.HandleFunc("/feedingTimes", ReturnAllFeedingTimes).Methods("GET")
myRouter.HandleFunc("/feedingTime/{id}", ReturnSingleFeedingTime).Methods("GET")

rest_log.Println("Listening on 127.0.0.1:6969")
rest_log.Println(http.ListenAndServe(":6969", myRouter).Error())
listenOn := "localhost:" + GetPORT()
rest_log.Println("Listening on " + listenOn)

rest_log.Println("Connect to " + GetFQDN() + " for more information")
rest_log.Println(http.ListenAndServe(listenOn, myRouter).Error())
}
4 changes: 3 additions & 1 deletion common/common-names.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{
"log_filepath":"/tmp/cat-feeder.log"
"log_filepath":"/tmp/cat-feeder.log",
"FQDN":"https://canescent-saola-6329.dataplicity.io/",
"PORT":"80"
}
35 changes: 35 additions & 0 deletions task.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# All
- [ ] loera - 007: Create a logger for both the machine and app
* [ ] It should rollover any existing logs and then create a new log
- [ ] 008: Update the configuration to install what is needed and where executables/logs should be stored in
- [ ] loera - 011: Create a method sharing common variables between the app and machine
* In TID007, both of them use the file name "/tmp/cat-feeder.log", this should be shared instead of written in both of them

# Machine
- [x] loera - 001: Monitor the time
* [x] Only feed cat specified time, then keep feeder closed for the rest of the time
* [x] Make sure to lock/unlock `[]feeder_times` since it's used in both monitoring and REST API thread
- [ ] loera - 002: Create REST API
* [x] POST new feeding times
* [x] GET all/single feeding times
* [ ] POST to feed cat
- [ ] 003: Get them servo motors working
* [ ] Get the motor to open and close
* [ ] Add it to the monitoring
- [ ] 005: Communication from machine and app
* Over WiFi?
* Bluetooth?
* Host app on a webserver and let the user navigate to webpage?
- [ ] 009: Update `/feedNow` REST API to use the servo motors

# App
- [ ] 004: Continue development:
* [ ] Delete time in table
* [ ] Edit time in table
* [ ] Check if time is valid
* [ ] Allow 24 hour and 12 hour (AM/PM)
> Currently, only has 24 hour
- [ ] 006: Add button to feed
* Send command to feed cat
* Tell Christian to finish up the REST API to start this
- [ ] 010: Display last time fed on a label