From 2b9c41da35d3be71cc696de6f2575a9f22e1afec Mon Sep 17 00:00:00 2001 From: Christian Loera Date: Tue, 25 Aug 2020 11:18:25 -0500 Subject: [PATCH 01/28] Create task.md task.md explains the task that need to be done --- task.md | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 task.md diff --git a/task.md b/task.md new file mode 100644 index 0000000..df19336 --- /dev/null +++ b/task.md @@ -0,0 +1,32 @@ +# All +- [ ] loera - 007: Create a logger for both the machine and app + * [ ] It should rollover any existing logs and then create a new log + > Currently have the machine logs completed, still working on the app portion +- [ ] loera - 008: Update the configuration to install what is needed and where executables/logs should be stored in + +# 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 +- [ ] loera - 003: Get them servo motors working + * [ ] Get the motor to open and close + * [ ] Add it to the monitoring +- [ ] loera - 005: Communication from machine and app + * Over WiFi? + * Bluetooth? + * Host app on a webserver and let the user navigate to webpage? + +# 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 From 1ea17d598b2b3ac30c6d4b2817f4b9e96151d1aa Mon Sep 17 00:00:00 2001 From: loerac Date: Tue, 25 Aug 2020 11:38:41 -0500 Subject: [PATCH 02/28] Added post request to feed cat now --- catfeeder-machine/rest-api.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/catfeeder-machine/rest-api.go b/catfeeder-machine/rest-api.go index 1ef96ae..ace221b 100644 --- a/catfeeder-machine/rest-api.go +++ b/catfeeder-machine/rest-api.go @@ -36,6 +36,13 @@ func CreateNewFeedTime(w http.ResponseWriter, r *http.Request) { PrintFeedingTimes(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. **/ @@ -74,6 +81,7 @@ 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/'") } @@ -85,6 +93,7 @@ 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") log.Fatal(http.ListenAndServe(":6969", myRouter)) From 4869e4567c640b7017fa3e38ddd0aad1e0528f15 Mon Sep 17 00:00:00 2001 From: Christian Loera Date: Tue, 25 Aug 2020 11:54:22 -0500 Subject: [PATCH 03/28] Added task TID #009 to update REST API Once TID #003 is complete, update the "/feedNow" REST API to use the servo motors --- task.md | 1 + 1 file changed, 1 insertion(+) diff --git a/task.md b/task.md index df19336..137e1ea 100644 --- a/task.md +++ b/task.md @@ -19,6 +19,7 @@ * Over WiFi? * Bluetooth? * Host app on a webserver and let the user navigate to webpage? +- [ ] loera - 009: Update `/feedNow` REST API to use the servo motors # App - [ ] 004: Continue development: From 59c852686c600310e0b93df3cc1714c147d5ec22 Mon Sep 17 00:00:00 2001 From: Christian Loera Date: Tue, 25 Aug 2020 11:55:21 -0500 Subject: [PATCH 04/28] Remove myself from TID #009 I don't want to hog up the work, should let team also contribute to this as well --- task.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/task.md b/task.md index 137e1ea..cf90d22 100644 --- a/task.md +++ b/task.md @@ -19,7 +19,7 @@ * Over WiFi? * Bluetooth? * Host app on a webserver and let the user navigate to webpage? -- [ ] loera - 009: Update `/feedNow` REST API to use the servo motors +- [ ] 009: Update `/feedNow` REST API to use the servo motors # App - [ ] 004: Continue development: From 3f95211f60c48f39a50b8002d3ad5a09e2e99b61 Mon Sep 17 00:00:00 2001 From: loerac Date: Tue, 25 Aug 2020 12:03:10 -0500 Subject: [PATCH 05/28] Updated function name to match API call --- catfeeder-machine/rest-api.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/catfeeder-machine/rest-api.go b/catfeeder-machine/rest-api.go index ace221b..d247d26 100644 --- a/catfeeder-machine/rest-api.go +++ b/catfeeder-machine/rest-api.go @@ -39,7 +39,7 @@ func CreateNewFeedTime(w http.ResponseWriter, r *http.Request) { /*** * @brief: Handle to feed the cat. ***/ -func CreateFeednow(w http.ResponseWriter, r *http.Request) { +func CreateFeedNow(w http.ResponseWriter, r *http.Request) { fmt.Println("Place holder to feed cat now, will update once TID003 is complete") } @@ -93,7 +93,7 @@ func HandleRequests() { myRouter := mux.NewRouter().StrictSlash(true) myRouter.HandleFunc("/", HomePage) myRouter.HandleFunc("/feedingTime", CreateNewFeedTime).Methods("POST") - myRouter.HandleFunc("/feedNow", CreateFeednow).Methods("POST") + myRouter.HandleFunc("/feedNow", CreateFeedNow).Methods("POST") myRouter.HandleFunc("/feedingTimes", ReturnAllFeedingTimes).Methods("GET") myRouter.HandleFunc("/feedingTime/{id}", ReturnSingleFeedingTime).Methods("GET") log.Fatal(http.ListenAndServe(":6969", myRouter)) From 357fa070ca04005f2525368d9a293badab87e09d Mon Sep 17 00:00:00 2001 From: loerac Date: Tue, 25 Aug 2020 12:04:14 -0500 Subject: [PATCH 06/28] Updated description to say 'return' instead of 'recieve' --- catfeeder-machine/rest-api.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/catfeeder-machine/rest-api.go b/catfeeder-machine/rest-api.go index d247d26..e93bceb 100644 --- a/catfeeder-machine/rest-api.go +++ b/catfeeder-machine/rest-api.go @@ -44,7 +44,7 @@ func CreateFeedNow(w http.ResponseWriter, r *http.Request) { } /** - * @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) @@ -64,7 +64,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() @@ -75,7 +75,7 @@ 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") From 6ea66aae5c0e9c516ea7a6bac8719ef34560e00c Mon Sep 17 00:00:00 2001 From: Christian Loera Date: Tue, 25 Aug 2020 16:25:28 -0500 Subject: [PATCH 07/28] Added new TID for app Added new TID for app to display the last time the cat was fed --- task.md | 1 + 1 file changed, 1 insertion(+) diff --git a/task.md b/task.md index cf90d22..67f85f9 100644 --- a/task.md +++ b/task.md @@ -31,3 +31,4 @@ - [ ] 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 From 5f2105be16cda057fcc83425e883dfbbc111b299 Mon Sep 17 00:00:00 2001 From: Christian Loera Date: Thu, 27 Aug 2020 09:48:14 -0500 Subject: [PATCH 08/28] Added new TID 011 Share variables between the app and the machine --- task.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/task.md b/task.md index 67f85f9..0f3fbb0 100644 --- a/task.md +++ b/task.md @@ -1,8 +1,9 @@ # All - [ ] loera - 007: Create a logger for both the machine and app * [ ] It should rollover any existing logs and then create a new log - > Currently have the machine logs completed, still working on the app portion -- [ ] loera - 008: Update the configuration to install what is needed and where executables/logs should be stored in +- [ ] 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 @@ -12,10 +13,10 @@ * [x] POST new feeding times * [x] GET all/single feeding times * [ ] POST to feed cat -- [ ] loera - 003: Get them servo motors working +- [ ] 003: Get them servo motors working * [ ] Get the motor to open and close * [ ] Add it to the monitoring -- [ ] loera - 005: Communication from machine and app +- [ ] 005: Communication from machine and app * Over WiFi? * Bluetooth? * Host app on a webserver and let the user navigate to webpage? From 9170806c6667e13fd41a919918178244dba89e34 Mon Sep 17 00:00:00 2001 From: loerac Date: Fri, 28 Aug 2020 22:32:33 -0500 Subject: [PATCH 09/28] Use TLS for dataplicity Create a class that will initialize the SSL version to use TLSv1.2 --- catfeeder-app/TLSAdapter.py | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 catfeeder-app/TLSAdapter.py diff --git a/catfeeder-app/TLSAdapter.py b/catfeeder-app/TLSAdapter.py new file mode 100644 index 0000000..6c59c05 --- /dev/null +++ b/catfeeder-app/TLSAdapter.py @@ -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) From e1ddc9164b92d2edd7c8605419ba4f75a7e4ac1e Mon Sep 17 00:00:00 2001 From: loerac Date: Fri, 28 Aug 2020 22:32:48 -0500 Subject: [PATCH 10/28] Use TLS for requests --- catfeeder-app/src/catfeeder/app.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/catfeeder-app/src/catfeeder/app.py b/catfeeder-app/src/catfeeder/app.py index 3018bc0..e0232aa 100644 --- a/catfeeder-app/src/catfeeder/app.py +++ b/catfeeder-app/src/catfeeder/app.py @@ -4,15 +4,18 @@ import toga import requests import json +import TSLAdapter from toga.style import Pack from toga.style.pack import COLUMN, ROW -BASE_URL = "http://localhost:6969" +BASE_URL = "https://canescent-saola-6329.dataplicity.io" CREATE_TIME = BASE_URL + "/feedingTime" RECIEVE_A_TIME = BASE_URL + "/feedingTime" RECIEVE_ALL_TIMES = BASE_URL + "/feedingTimes" feeding_times = [] +cat_session = requests.Session() +cat_session.mount(BASE_URL, TLSAdapter.Tls12HttpAdapter()) class CatFeeder(toga.App): # TODO: Come up with better variable names @@ -111,7 +114,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)) ) @@ -132,10 +135,10 @@ def getFeedingTimes(self, widget): self.time_table.data.clear() try: - req = requests.get(url = RECIEVE_ALL_TIMES) - if req == None: + req = cat_session.get(url = RECIEVE_ALL_TIMES) + if req.json() is None: print("Uh oh! Things not looking good") - self.error_label.text = "Received invalid feeding times:", req + self.error_label.text = "Received invalid feeding times:", str(req) return if req.status_code != 200: print("Uh oh! Not success:", req.status_code) From 719b7096360759f988492256842bbdd512da5e8f Mon Sep 17 00:00:00 2001 From: loerac Date: Fri, 28 Aug 2020 22:33:09 -0500 Subject: [PATCH 11/28] Use dataplicity wormhole on port 80 --- catfeeder-machine/rest-api.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/catfeeder-machine/rest-api.go b/catfeeder-machine/rest-api.go index e93bceb..69bc13a 100644 --- a/catfeeder-machine/rest-api.go +++ b/catfeeder-machine/rest-api.go @@ -96,5 +96,5 @@ func HandleRequests() { myRouter.HandleFunc("/feedNow", CreateFeedNow).Methods("POST") myRouter.HandleFunc("/feedingTimes", ReturnAllFeedingTimes).Methods("GET") myRouter.HandleFunc("/feedingTime/{id}", ReturnSingleFeedingTime).Methods("GET") - log.Fatal(http.ListenAndServe(":6969", myRouter)) + log.Fatal(http.ListenAndServe("https://canescent-saola-6329.dataplicity.io:80", myRouter)) } From f3fc8cda764470d4bd0a4c744c3524b844379a47 Mon Sep 17 00:00:00 2001 From: loerac Date: Fri, 28 Aug 2020 22:42:00 -0500 Subject: [PATCH 12/28] Spelled TLS incorrectly... --- catfeeder-app/src/catfeeder/app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/catfeeder-app/src/catfeeder/app.py b/catfeeder-app/src/catfeeder/app.py index e0232aa..953bac3 100644 --- a/catfeeder-app/src/catfeeder/app.py +++ b/catfeeder-app/src/catfeeder/app.py @@ -4,7 +4,7 @@ import toga import requests import json -import TSLAdapter +import TLSAdapter from toga.style import Pack from toga.style.pack import COLUMN, ROW From fd168eb63526703aea126b966dfa59e1ef3b5477 Mon Sep 17 00:00:00 2001 From: loerac Date: Sat, 29 Aug 2020 08:44:19 -0500 Subject: [PATCH 13/28] Remove cache --- .../__pycache__/__init__.cpython-36.pyc | Bin 157 -> 0 bytes .../__pycache__/__main__.cpython-36.pyc | Bin 252 -> 0 bytes .../src/catfeeder/__pycache__/app.cpython-36.pyc | Bin 4454 -> 0 bytes 3 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 catfeeder-app/src/catfeeder/__pycache__/__init__.cpython-36.pyc delete mode 100644 catfeeder-app/src/catfeeder/__pycache__/__main__.cpython-36.pyc delete mode 100644 catfeeder-app/src/catfeeder/__pycache__/app.cpython-36.pyc diff --git a/catfeeder-app/src/catfeeder/__pycache__/__init__.cpython-36.pyc b/catfeeder-app/src/catfeeder/__pycache__/__init__.cpython-36.pyc deleted file mode 100644 index 5f7b71bc074e805a6533bd1cdba0017f73aabdf5..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 157 zcmXr!<>h+mVjs@{1dl-k3@`#24nSPY0whuxf*CX!{Z=v*frJsnFE9O!{M=OiM2371j)($&XU!e1mQR$JCHgN#`9bt#vo>ZN9zbxs-crNM`%oIO)7C rC_7bhXC=diA6jESZpd6&`Ru=u-v>tSQil^`^|_=eGQJ8}dLqOZU+P24 diff --git a/catfeeder-app/src/catfeeder/__pycache__/app.cpython-36.pyc b/catfeeder-app/src/catfeeder/__pycache__/app.cpython-36.pyc deleted file mode 100644 index bdaa944d28b7ec6bcd404a347a77536faad748a0..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 4454 zcmcIo%W@mX743OqW&jX;i4Vn+CsAH-Y*Myk#b#70Q4DFTilR~y6}hI8OhM=&IUq0t z^)y5Y1=>r`dsMZO`+tY@1Qf5EGq+cN?{Cff|FyKmoq-R?g3+y+0b*S)Q` z_rtqOjQyKUeJ14lNZBi7oCS<)T<>aurb<1~RcQnUN~3G`tiaN!kJ+_*m7vmd0ta;~ za3h!7%PjE9vWl{TdhL(}^)DHBxcioIH_|#YXGYNA9TM=|tKau! z>K{ZA_vKOKw_7svE?^ehYihaq`&Rq7spt0AP&D)sj0{HWF47t#kdo^_f$1X^{1?WQ-+qEEOlA zb>=$@auFxIaIULUqWU$y$giooq1q>P^Ge;iT!-aLuydI&ooldZWrV!560TC-xqimr zBn&WF-Wx7#Co&QW=0K<~0nv>MLdwM=G9bLtZ*c-|UM+=CrhRyTmB}~VC@{ZD2coG7 zNA(V>{cfur9i?3WPtY`h{U}ZbG8#IY9FBzPn|k1+N!S-rmZ>ho>Q*;u3DuYl-KSAf zbR4>0MzYZE4C@4DvXGo8qdAVE7Adlz(HnGS-0wzV7ImYx%*kw*#{zPkCc>rNSjs+8 zLs8g@9mrUAqvnrtQ>KTlz<7|p4y@hQi>NEe69acYdMzI&{ejHABkVGamF)K7q!bMt zO<+G5NSP*i1r;(b_u90b{nm?als7W$rZinOx}*qSU`XCLjFgLF6KYd=B}!-z53FLa zCox?p)kIaCXDY(3GLH^6w+DUR!rd9PB_htid(?`P=W)W*lc0K#ie9T5Caqo+RC{O$ zPl}dGJH?eJGBC5F^rY$KCXVeOa8#ccI0Hv5t0b~BB*|4)DA9?NgH%a{eafU@4!Z|3 z3TxH=f?0JA(;5dmR&9S{;sz}KVSD{3?M3VDqqx^!?~Am9E6dgo({-@zN5q z0wu3!qCL^9L$lU@lUFj?5^~UAz?|7GGNw82{`4hdNn6r9t)|uV6>UYkj^v9YHzq2Q*uz9#hKCB$gk2Aj)XBi+lTq+#*s($~1;)$Sa=1I*!(F?5|m(f6WjoXAt6b?jRsj zKX=lv>FpIDo7qc?AmAUyuYe98n{67o9`oEJTFz|{G9nB}-x!Flx`E;C$4|G3FgN^X zM}B(rV}CbIk2Aj;A4mS1bl|r{j!%n)vOs*Bc};cn4VZPhxrG z_gbK+BpS{mILXVwQn?V||8tmC-0e>w<(6nAhrn|tMQ)HU{FJngh+Yn&OlE=E$NMm^ zZavxF+}{rOA3oa7%}$0eV(~$*pXHTu0}A<~Nqcq_@D+%Hc@;)3`BR`D$O3)_R>=(n zjNC+!?Oz4kHB9ybDf=a|(mB9`^SZ6gXp6>-t^>*c?Gh#l z$qJKqzz|oR=FK0a(J`gPwR7#%7#W;_C+|tSU_AM9;fAAnzQ(YA#UR!hc`>~?gM>?nV+Q6?*hn#%fmF~!}p&=?Fe4M0cJ37 z%r9Xx+qn2A&9YF=vWMZ>pxws9Yh!qQrxoL^LBDbEP>Q2h5lRKljsKJPh&31^)+zHT zQz2v-JD|m{TE1WS)#8Lz#fLQL*T`~%h=1j|t`YuRKZt2R#=#0KY$|x{0 zZ8|_rBKTg@&7Dv^JHs&d!myX}0iNbzUJJvQgI1Rwq+uxD#}q0|3t|jGoFwSvikq0M ztRxlF>77LpFRLMQbmuc?-f^58&J95=ZKUx>$Wo_6;Z(9S+P6kdMLnnPYdm>w((CuH zXe~D Date: Tue, 25 Aug 2020 11:18:25 -0500 Subject: [PATCH 14/28] Create task.md task.md explains the task that need to be done --- task.md | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 task.md diff --git a/task.md b/task.md new file mode 100644 index 0000000..df19336 --- /dev/null +++ b/task.md @@ -0,0 +1,32 @@ +# All +- [ ] loera - 007: Create a logger for both the machine and app + * [ ] It should rollover any existing logs and then create a new log + > Currently have the machine logs completed, still working on the app portion +- [ ] loera - 008: Update the configuration to install what is needed and where executables/logs should be stored in + +# 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 +- [ ] loera - 003: Get them servo motors working + * [ ] Get the motor to open and close + * [ ] Add it to the monitoring +- [ ] loera - 005: Communication from machine and app + * Over WiFi? + * Bluetooth? + * Host app on a webserver and let the user navigate to webpage? + +# 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 From 7b6db03d3478280aed2e586dcb20575a6d5113d0 Mon Sep 17 00:00:00 2001 From: loerac Date: Tue, 25 Aug 2020 11:38:41 -0500 Subject: [PATCH 15/28] Added post request to feed cat now --- catfeeder-machine/rest-api.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/catfeeder-machine/rest-api.go b/catfeeder-machine/rest-api.go index 8d6e289..de310ac 100644 --- a/catfeeder-machine/rest-api.go +++ b/catfeeder-machine/rest-api.go @@ -40,6 +40,13 @@ 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. **/ @@ -75,6 +82,7 @@ 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/'") } @@ -88,6 +96,7 @@ 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") From fc1fb187fb2fc12f280ed51f2e4f9009187786cc Mon Sep 17 00:00:00 2001 From: Christian Loera Date: Tue, 25 Aug 2020 11:54:22 -0500 Subject: [PATCH 16/28] Added task TID #009 to update REST API Once TID #003 is complete, update the "/feedNow" REST API to use the servo motors --- task.md | 1 + 1 file changed, 1 insertion(+) diff --git a/task.md b/task.md index df19336..137e1ea 100644 --- a/task.md +++ b/task.md @@ -19,6 +19,7 @@ * Over WiFi? * Bluetooth? * Host app on a webserver and let the user navigate to webpage? +- [ ] loera - 009: Update `/feedNow` REST API to use the servo motors # App - [ ] 004: Continue development: From 7dc5434248bf22b624a9d374dddbad0dd197234f Mon Sep 17 00:00:00 2001 From: Christian Loera Date: Tue, 25 Aug 2020 11:55:21 -0500 Subject: [PATCH 17/28] Remove myself from TID #009 I don't want to hog up the work, should let team also contribute to this as well --- task.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/task.md b/task.md index 137e1ea..cf90d22 100644 --- a/task.md +++ b/task.md @@ -19,7 +19,7 @@ * Over WiFi? * Bluetooth? * Host app on a webserver and let the user navigate to webpage? -- [ ] loera - 009: Update `/feedNow` REST API to use the servo motors +- [ ] 009: Update `/feedNow` REST API to use the servo motors # App - [ ] 004: Continue development: From c751f6bd1ecec7789e1c319fbfe3ed6d6e9609f5 Mon Sep 17 00:00:00 2001 From: loerac Date: Tue, 25 Aug 2020 12:03:10 -0500 Subject: [PATCH 18/28] Updated function name to match API call --- catfeeder-machine/rest-api.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/catfeeder-machine/rest-api.go b/catfeeder-machine/rest-api.go index de310ac..8757f86 100644 --- a/catfeeder-machine/rest-api.go +++ b/catfeeder-machine/rest-api.go @@ -43,7 +43,7 @@ func CreateNewFeedTime(w http.ResponseWriter, r *http.Request) { /*** * @brief: Handle to feed the cat. ***/ -func CreateFeednow(w http.ResponseWriter, r *http.Request) { +func CreateFeedNow(w http.ResponseWriter, r *http.Request) { fmt.Println("Place holder to feed cat now, will update once TID003 is complete") } @@ -96,7 +96,7 @@ func HandleRequests() { myRouter := mux.NewRouter().StrictSlash(true) myRouter.HandleFunc("/", HomePage) myRouter.HandleFunc("/feedingTime", CreateNewFeedTime).Methods("POST") - myRouter.HandleFunc("/feedNow", CreateFeednow).Methods("POST") + myRouter.HandleFunc("/feedNow", CreateFeedNow).Methods("POST") myRouter.HandleFunc("/feedingTimes", ReturnAllFeedingTimes).Methods("GET") myRouter.HandleFunc("/feedingTime/{id}", ReturnSingleFeedingTime).Methods("GET") From 66e0a7d45cf763c0beb1fc2d02f9ab350d61966a Mon Sep 17 00:00:00 2001 From: loerac Date: Tue, 25 Aug 2020 12:04:14 -0500 Subject: [PATCH 19/28] Updated description to say 'return' instead of 'recieve' --- catfeeder-machine/rest-api.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/catfeeder-machine/rest-api.go b/catfeeder-machine/rest-api.go index 8757f86..2e81b4d 100644 --- a/catfeeder-machine/rest-api.go +++ b/catfeeder-machine/rest-api.go @@ -48,7 +48,7 @@ func CreateFeedNow(w http.ResponseWriter, r *http.Request) { } /** - * @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) @@ -66,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() @@ -76,7 +76,7 @@ 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") From 9e2eaae69504416e1b8811a978e3568491eeb49a Mon Sep 17 00:00:00 2001 From: Christian Loera Date: Tue, 25 Aug 2020 16:25:28 -0500 Subject: [PATCH 20/28] Added new TID for app Added new TID for app to display the last time the cat was fed --- task.md | 1 + 1 file changed, 1 insertion(+) diff --git a/task.md b/task.md index cf90d22..67f85f9 100644 --- a/task.md +++ b/task.md @@ -31,3 +31,4 @@ - [ ] 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 From 5e3dd99688fdf8a63a8f4adae45bef2c58736715 Mon Sep 17 00:00:00 2001 From: Christian Loera Date: Thu, 27 Aug 2020 09:48:14 -0500 Subject: [PATCH 21/28] Added new TID 011 Share variables between the app and the machine --- task.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/task.md b/task.md index 67f85f9..0f3fbb0 100644 --- a/task.md +++ b/task.md @@ -1,8 +1,9 @@ # All - [ ] loera - 007: Create a logger for both the machine and app * [ ] It should rollover any existing logs and then create a new log - > Currently have the machine logs completed, still working on the app portion -- [ ] loera - 008: Update the configuration to install what is needed and where executables/logs should be stored in +- [ ] 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 @@ -12,10 +13,10 @@ * [x] POST new feeding times * [x] GET all/single feeding times * [ ] POST to feed cat -- [ ] loera - 003: Get them servo motors working +- [ ] 003: Get them servo motors working * [ ] Get the motor to open and close * [ ] Add it to the monitoring -- [ ] loera - 005: Communication from machine and app +- [ ] 005: Communication from machine and app * Over WiFi? * Bluetooth? * Host app on a webserver and let the user navigate to webpage? From 1f7437c78a5505fd36020f1d127e1077ff0e1b78 Mon Sep 17 00:00:00 2001 From: loerac Date: Fri, 28 Aug 2020 22:32:33 -0500 Subject: [PATCH 22/28] Use TLS for dataplicity Create a class that will initialize the SSL version to use TLSv1.2 --- catfeeder-app/TLSAdapter.py | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 catfeeder-app/TLSAdapter.py diff --git a/catfeeder-app/TLSAdapter.py b/catfeeder-app/TLSAdapter.py new file mode 100644 index 0000000..6c59c05 --- /dev/null +++ b/catfeeder-app/TLSAdapter.py @@ -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) From dc1a5017f69034330805063e209aaa66f29f5398 Mon Sep 17 00:00:00 2001 From: loerac Date: Sat, 29 Aug 2020 08:56:06 -0500 Subject: [PATCH 23/28] Resolve conflicts after rebase of TID011-common-libs --- catfeeder-app/src/catfeeder/app.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/catfeeder-app/src/catfeeder/app.py b/catfeeder-app/src/catfeeder/app.py index 331a0cb..be8a013 100644 --- a/catfeeder-app/src/catfeeder/app.py +++ b/catfeeder-app/src/catfeeder/app.py @@ -5,16 +5,19 @@ import requests import toga import utils +import TSLAdapter from toga.style import Pack from toga.style.pack import COLUMN, ROW -BASE_URL = "http://localhost:6969" +BASE_URL = "https://canescent-saola-6329.dataplicity.io" 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 @@ -113,7 +116,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)) ) @@ -131,10 +134,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) + ")") From 37e89e45a275e008cfd9a0211a163ac4b342cf1d Mon Sep 17 00:00:00 2001 From: loerac Date: Fri, 28 Aug 2020 22:33:09 -0500 Subject: [PATCH 24/28] Use dataplicity wormhole on port 80 --- catfeeder-machine/rest-api.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/catfeeder-machine/rest-api.go b/catfeeder-machine/rest-api.go index 2e81b4d..3fa22c0 100644 --- a/catfeeder-machine/rest-api.go +++ b/catfeeder-machine/rest-api.go @@ -100,6 +100,6 @@ func HandleRequests() { 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()) + rest_log.Println("Listening on https://canescent-saola-6329.dataplicity.io:80") + rest_log.Println(http.ListenAndServe("https://canescent-saola-6329.dataplicity.io:80", myRouter).Error()) } From 4acc4ffc1505c87e7f24b2d64cf2611248d43bb7 Mon Sep 17 00:00:00 2001 From: loerac Date: Fri, 28 Aug 2020 22:42:00 -0500 Subject: [PATCH 25/28] Spelled TLS incorrectly... --- catfeeder-app/src/catfeeder/app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/catfeeder-app/src/catfeeder/app.py b/catfeeder-app/src/catfeeder/app.py index be8a013..dffbbaf 100644 --- a/catfeeder-app/src/catfeeder/app.py +++ b/catfeeder-app/src/catfeeder/app.py @@ -5,7 +5,7 @@ import requests import toga import utils -import TSLAdapter +import TLSAdapter from toga.style import Pack from toga.style.pack import COLUMN, ROW From 378d251b7ef8ad329200fdf9a62fc1ae3838504f Mon Sep 17 00:00:00 2001 From: loerac Date: Sat, 29 Aug 2020 08:44:19 -0500 Subject: [PATCH 26/28] Remove cache --- .../__pycache__/__init__.cpython-36.pyc | Bin 157 -> 0 bytes .../__pycache__/__main__.cpython-36.pyc | Bin 252 -> 0 bytes .../src/catfeeder/__pycache__/app.cpython-36.pyc | Bin 4454 -> 0 bytes 3 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 catfeeder-app/src/catfeeder/__pycache__/__init__.cpython-36.pyc delete mode 100644 catfeeder-app/src/catfeeder/__pycache__/__main__.cpython-36.pyc delete mode 100644 catfeeder-app/src/catfeeder/__pycache__/app.cpython-36.pyc diff --git a/catfeeder-app/src/catfeeder/__pycache__/__init__.cpython-36.pyc b/catfeeder-app/src/catfeeder/__pycache__/__init__.cpython-36.pyc deleted file mode 100644 index 5f7b71bc074e805a6533bd1cdba0017f73aabdf5..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 157 zcmXr!<>h+mVjs@{1dl-k3@`#24nSPY0whuxf*CX!{Z=v*frJsnFE9O!{M=OiM2371j)($&XU!e1mQR$JCHgN#`9bt#vo>ZN9zbxs-crNM`%oIO)7C rC_7bhXC=diA6jESZpd6&`Ru=u-v>tSQil^`^|_=eGQJ8}dLqOZU+P24 diff --git a/catfeeder-app/src/catfeeder/__pycache__/app.cpython-36.pyc b/catfeeder-app/src/catfeeder/__pycache__/app.cpython-36.pyc deleted file mode 100644 index bdaa944d28b7ec6bcd404a347a77536faad748a0..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 4454 zcmcIo%W@mX743OqW&jX;i4Vn+CsAH-Y*Myk#b#70Q4DFTilR~y6}hI8OhM=&IUq0t z^)y5Y1=>r`dsMZO`+tY@1Qf5EGq+cN?{Cff|FyKmoq-R?g3+y+0b*S)Q` z_rtqOjQyKUeJ14lNZBi7oCS<)T<>aurb<1~RcQnUN~3G`tiaN!kJ+_*m7vmd0ta;~ za3h!7%PjE9vWl{TdhL(}^)DHBxcioIH_|#YXGYNA9TM=|tKau! z>K{ZA_vKOKw_7svE?^ehYihaq`&Rq7spt0AP&D)sj0{HWF47t#kdo^_f$1X^{1?WQ-+qEEOlA zb>=$@auFxIaIULUqWU$y$giooq1q>P^Ge;iT!-aLuydI&ooldZWrV!560TC-xqimr zBn&WF-Wx7#Co&QW=0K<~0nv>MLdwM=G9bLtZ*c-|UM+=CrhRyTmB}~VC@{ZD2coG7 zNA(V>{cfur9i?3WPtY`h{U}ZbG8#IY9FBzPn|k1+N!S-rmZ>ho>Q*;u3DuYl-KSAf zbR4>0MzYZE4C@4DvXGo8qdAVE7Adlz(HnGS-0wzV7ImYx%*kw*#{zPkCc>rNSjs+8 zLs8g@9mrUAqvnrtQ>KTlz<7|p4y@hQi>NEe69acYdMzI&{ejHABkVGamF)K7q!bMt zO<+G5NSP*i1r;(b_u90b{nm?als7W$rZinOx}*qSU`XCLjFgLF6KYd=B}!-z53FLa zCox?p)kIaCXDY(3GLH^6w+DUR!rd9PB_htid(?`P=W)W*lc0K#ie9T5Caqo+RC{O$ zPl}dGJH?eJGBC5F^rY$KCXVeOa8#ccI0Hv5t0b~BB*|4)DA9?NgH%a{eafU@4!Z|3 z3TxH=f?0JA(;5dmR&9S{;sz}KVSD{3?M3VDqqx^!?~Am9E6dgo({-@zN5q z0wu3!qCL^9L$lU@lUFj?5^~UAz?|7GGNw82{`4hdNn6r9t)|uV6>UYkj^v9YHzq2Q*uz9#hKCB$gk2Aj)XBi+lTq+#*s($~1;)$Sa=1I*!(F?5|m(f6WjoXAt6b?jRsj zKX=lv>FpIDo7qc?AmAUyuYe98n{67o9`oEJTFz|{G9nB}-x!Flx`E;C$4|G3FgN^X zM}B(rV}CbIk2Aj;A4mS1bl|r{j!%n)vOs*Bc};cn4VZPhxrG z_gbK+BpS{mILXVwQn?V||8tmC-0e>w<(6nAhrn|tMQ)HU{FJngh+Yn&OlE=E$NMm^ zZavxF+}{rOA3oa7%}$0eV(~$*pXHTu0}A<~Nqcq_@D+%Hc@;)3`BR`D$O3)_R>=(n zjNC+!?Oz4kHB9ybDf=a|(mB9`^SZ6gXp6>-t^>*c?Gh#l z$qJKqzz|oR=FK0a(J`gPwR7#%7#W;_C+|tSU_AM9;fAAnzQ(YA#UR!hc`>~?gM>?nV+Q6?*hn#%fmF~!}p&=?Fe4M0cJ37 z%r9Xx+qn2A&9YF=vWMZ>pxws9Yh!qQrxoL^LBDbEP>Q2h5lRKljsKJPh&31^)+zHT zQz2v-JD|m{TE1WS)#8Lz#fLQL*T`~%h=1j|t`YuRKZt2R#=#0KY$|x{0 zZ8|_rBKTg@&7Dv^JHs&d!myX}0iNbzUJJvQgI1Rwq+uxD#}q0|3t|jGoFwSvikq0M ztRxlF>77LpFRLMQbmuc?-f^58&J95=ZKUx>$Wo_6;Z(9S+P6kdMLnnPYdm>w((CuH zXe~D Date: Sat, 29 Aug 2020 09:55:52 -0500 Subject: [PATCH 27/28] FQDN and port updates Server is running on port 80 FQDN is used to interface with the server JSON file updated to store these values --- catfeeder-machine/common.go | 20 ++++++++++++++++++++ catfeeder-machine/rest-api.go | 14 +++++--------- common/common-names.json | 4 +++- 3 files changed, 28 insertions(+), 10 deletions(-) diff --git a/catfeeder-machine/common.go b/catfeeder-machine/common.go index 22d070e..ec48569 100644 --- a/catfeeder-machine/common.go +++ b/catfeeder-machine/common.go @@ -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 @@ -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 +} diff --git a/catfeeder-machine/rest-api.go b/catfeeder-machine/rest-api.go index 21fabe3..5c98527 100644 --- a/catfeeder-machine/rest-api.go +++ b/catfeeder-machine/rest-api.go @@ -47,13 +47,6 @@ func CreateFeedNow(w http.ResponseWriter, r *http.Request) { fmt.Println("Place holder to feed cat now, will update once TID003 is complete") } -/*** - * @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 returning a specific feeding time. **/ @@ -107,6 +100,9 @@ func HandleRequests() { myRouter.HandleFunc("/feedingTimes", ReturnAllFeedingTimes).Methods("GET") myRouter.HandleFunc("/feedingTime/{id}", ReturnSingleFeedingTime).Methods("GET") - rest_log.Println("Listening on https://canescent-saola-6329.dataplicity.io:80") - rest_log.Println(http.ListenAndServe("https://canescent-saola-6329.dataplicity.io:80", 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()) } diff --git a/common/common-names.json b/common/common-names.json index d4bbc81..cd897ed 100644 --- a/common/common-names.json +++ b/common/common-names.json @@ -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" } From edc41dc454e2099025fb393550c5b4ec4af97539 Mon Sep 17 00:00:00 2001 From: loerac Date: Sat, 29 Aug 2020 10:02:21 -0500 Subject: [PATCH 28/28] Use the FQDN to send data to raspberry pi --- catfeeder-app/commonLibs.py | 6 ++++++ catfeeder-app/src/catfeeder/app.py | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/catfeeder-app/commonLibs.py b/catfeeder-app/commonLibs.py index a6c15c4..7978bea 100644 --- a/catfeeder-app/commonLibs.py +++ b/catfeeder-app/commonLibs.py @@ -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'] diff --git a/catfeeder-app/src/catfeeder/app.py b/catfeeder-app/src/catfeeder/app.py index dffbbaf..e83f168 100644 --- a/catfeeder-app/src/catfeeder/app.py +++ b/catfeeder-app/src/catfeeder/app.py @@ -1,6 +1,7 @@ """ An app to feed the cats """ +import commonLibs import json import requests import toga @@ -9,7 +10,7 @@ from toga.style import Pack from toga.style.pack import COLUMN, ROW -BASE_URL = "https://canescent-saola-6329.dataplicity.io" +BASE_URL = commonLibs.CommonLibs().GetFQDN() CREATE_TIME = BASE_URL + "/feedingTime" RECIEVE_A_TIME = BASE_URL + "/feedingTime" RECIEVE_ALL_TIMES = BASE_URL + "/feedingTimes"