Skip to content

Commit a3b7171

Browse files
committed
first commit
0 parents  commit a3b7171

File tree

12 files changed

+357
-0
lines changed

12 files changed

+357
-0
lines changed

.github/workflows/platformio.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: PlatformIO CI
2+
3+
on: [push]
4+
5+
jobs:
6+
build:
7+
runs-on: ubuntu-latest
8+
9+
steps:
10+
- uses: actions/checkout@v3
11+
- uses: actions/cache@v3
12+
with:
13+
path: |
14+
~/.cache/pip
15+
~/.platformio/.cache
16+
key: ${{ runner.os }}-pio
17+
- uses: actions/setup-python@v4
18+
with:
19+
python-version: "3.9"
20+
- name: Install PlatformIO Core
21+
run: pip install --upgrade platformio
22+
23+
- name: Build PlatformIO Project
24+
working-directory: ./controller/tea_poor
25+
run: pio run

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
controller/tea_poor/.pio
2+
**/.vscode/**
3+
.idea

ReadMe.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Project Tea

UNLICENSE

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
This is free and unencumbered software released into the public domain.
2+
3+
Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a compiled binary, for any purpose, commercial or non-commercial, and by any means.
4+
5+
In jurisdictions that recognize copyright laws, the author or authors of this software dedicate any and all copyright interest in the software to the public domain. We make this dedication for the benefit of the public at large and to the detriment of our heirs and successors. We intend this dedication to be an overt act of relinquishment in perpetuity of all present and future rights to this software under copyright law.
6+
7+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
8+
9+
For more information, please refer to <http://unlicense.org/>

controller/tea_poor/include/README

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
2+
This directory is intended for project header files.
3+
4+
A header file is a file containing C declarations and macro definitions
5+
to be shared between several project source files. You request the use of a
6+
header file in your project source file (C, C++, etc) located in `src` folder
7+
by including it, with the C preprocessing directive `#include'.
8+
9+
```src/main.c
10+
11+
#include "header.h"
12+
13+
int main (void)
14+
{
15+
...
16+
}
17+
```
18+
19+
Including a header file produces the same results as copying the header file
20+
into each source file that needs it. Such copying would be time-consuming
21+
and error-prone. With a header file, the related declarations appear
22+
in only one place. If they need to be changed, they can be changed in one
23+
place, and programs that include the header file will automatically use the
24+
new version when next recompiled. The header file eliminates the labor of
25+
finding and changing all the copies as well as the risk that a failure to
26+
find one copy will result in inconsistencies within a program.
27+
28+
In C, the usual convention is to give header files names that end with `.h'.
29+
It is most portable to use only letters, digits, dashes, and underscores in
30+
header file names, and at most one dot.
31+
32+
Read more about using header files in official GCC documentation:
33+
34+
* Include Syntax
35+
* Include Operation
36+
* Once-Only Headers
37+
* Computed Includes
38+
39+
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html

controller/tea_poor/lib/README

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
2+
This directory is intended for project specific (private) libraries.
3+
PlatformIO will compile them to static libraries and link into executable file.
4+
5+
The source code of each library should be placed in a an own separate directory
6+
("lib/your_library_name/[here are source files]").
7+
8+
For example, see a structure of the following two libraries `Foo` and `Bar`:
9+
10+
|--lib
11+
| |
12+
| |--Bar
13+
| | |--docs
14+
| | |--examples
15+
| | |--src
16+
| | |- Bar.c
17+
| | |- Bar.h
18+
| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
19+
| |
20+
| |--Foo
21+
| | |- Foo.c
22+
| | |- Foo.h
23+
| |
24+
| |- README --> THIS FILE
25+
|
26+
|- platformio.ini
27+
|--src
28+
|- main.c
29+
30+
and a contents of `src/main.c`:
31+
```
32+
#include <Foo.h>
33+
#include <Bar.h>
34+
35+
int main (void)
36+
{
37+
...
38+
}
39+
40+
```
41+
42+
PlatformIO Library Dependency Finder will find automatically dependent
43+
libraries scanning project source files.
44+
45+
More information about PlatformIO Library Dependency Finder
46+
- https://docs.platformio.org/page/librarymanager/ldf.html

controller/tea_poor/platformio.ini

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
; PlatformIO Project Configuration File
2+
;
3+
; Build options: build flags, source filter
4+
; Upload options: custom upload port, speed and extra flags
5+
; Library options: dependencies, extra library storages
6+
; Advanced options: extra scripting
7+
;
8+
; Please visit documentation for the other options and examples
9+
; https://docs.platformio.org/page/projectconf.html
10+
11+
[env:uno_r4_wifi]
12+
platform = renesas-ra
13+
board = uno_r4_wifi
14+
framework = arduino
15+
lib_deps =
16+
bblanchon/ArduinoJson@^6.21.4
17+
lasselukkari/aWOT@^3.5.0

controller/tea_poor/src/main.cpp

Lines changed: 205 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,205 @@
1+
#include <Arduino.h>
2+
#include <ArduinoJson.h>
3+
#include <WiFiS3.h>
4+
#include <aWOT.h>
5+
6+
// setting up WiFi
7+
const char *SSID = "MyWiFiNetwork";
8+
const char *PWD = "VerySecurePassword";
9+
10+
// Setting up Motorcontroller
11+
int directionPin = 12;
12+
int pwmPin = 3;
13+
int brakePin = 9;
14+
15+
// minimalistic webserver
16+
WiFiServer server(80);
17+
Application app;
18+
19+
// Start value Threshold for pouring
20+
int threshold_pour = 10;
21+
22+
void printMacAddress(byte mac[]) {
23+
for (int i = 0; i < 6; i++) {
24+
if (i > 0) {
25+
Serial.print(":");
26+
}
27+
if (mac[i] < 16) {
28+
Serial.print("0");
29+
}
30+
Serial.print(mac[i], HEX);
31+
}
32+
Serial.println();
33+
}
34+
35+
36+
void printCurrentNet() {
37+
// print the SSID of the network you're attached to:
38+
Serial.print("SSID: ");
39+
Serial.println(WiFi.SSID());
40+
41+
// print the MAC address of the router you're attached to:
42+
byte bssid[6];
43+
WiFi.BSSID(bssid);
44+
Serial.print("BSSID: ");
45+
printMacAddress(bssid);
46+
47+
// print the received signal strength:
48+
long rssi = WiFi.RSSI();
49+
Serial.print("signal strength (RSSI):");
50+
Serial.println(rssi);
51+
52+
// print the encryption type:
53+
byte encryption = WiFi.encryptionType();
54+
Serial.print("Encryption Type:");
55+
Serial.println(encryption, HEX);
56+
Serial.println();
57+
}
58+
59+
60+
void connectToWiFi() {
61+
62+
if (WiFi.status() == WL_NO_MODULE) {
63+
Serial.println("Communication with WiFi module failed!");
64+
// block further activity
65+
while(true);
66+
}
67+
68+
// info about your adapter
69+
String firmware_version = WiFi.firmwareVersion();
70+
71+
Serial.print("WiFi Firmware Version: ");
72+
Serial.println(firmware_version);
73+
if ( firmware_version < WIFI_FIRMWARE_LATEST_VERSION) {
74+
Serial.print("Latest available version: ");
75+
Serial.println(WIFI_FIRMWARE_LATEST_VERSION);
76+
Serial.println("Please upgrade your firmware.");
77+
}
78+
79+
80+
Serial.print("Connecting to ");
81+
Serial.println(SSID);
82+
83+
WiFi.begin(SSID, PWD);
84+
85+
while (WiFi.status() != WL_CONNECTED) {
86+
Serial.print(".");
87+
delay(500);
88+
// we can even make the ESP32 to sleep
89+
}
90+
91+
Serial.print("Connected. IP: ");
92+
Serial.println(WiFi.localIP());
93+
printCurrentNet();
94+
}
95+
96+
97+
98+
void set_threshold(Request &req, Response &res) {
99+
char seconds_char[64];
100+
req.query("seconds", seconds_char, 64);
101+
102+
if (strlen(seconds_char) != NULL){
103+
threshold_pour = atoi(seconds_char);
104+
res.print("You have reset the threshold! Please make sure that this is safe, as it aims to prevent overflow due to mistyping the query parameter. The threshold is now set to: ");
105+
res.print(threshold_pour);
106+
} else {
107+
res.print("Please specify amount of seconds in query parameter; threshold?seconds=10 e.g..");
108+
}
109+
}
110+
111+
void get_threshold(Request &req, Response &res) {
112+
res.print("The threshold is: ");
113+
res.print(threshold_pour);
114+
res.print(" seconds.");
115+
}
116+
117+
void pour_tea(Request &req, Response &res) {
118+
char seconds_char[64];
119+
req.query("seconds", seconds_char, 64);
120+
int pouring_delay = atoi(seconds_char);
121+
122+
if (strlen(seconds_char) != NULL && pouring_delay <= threshold_pour ){
123+
//release breaks
124+
digitalWrite(brakePin, LOW);
125+
126+
//set work duty for the motor, Duty is the amount of power it is getting from 0 to 256.
127+
analogWrite(pwmPin, 256);
128+
129+
delay(pouring_delay*1000); // convert miliseconds to seconds
130+
131+
//activate breaks
132+
digitalWrite(brakePin, HIGH);
133+
134+
//set work duty for the motor to 0 (off)
135+
analogWrite(pwmPin, 0);
136+
// Serial.println(req.JSON());
137+
res.print("Poured Tea in: ");
138+
res.print(pouring_delay);
139+
res.print(" seconds!");
140+
} else if (pouring_delay > threshold_pour) {
141+
res.print("Exceeded safety threshold for pouring. Change threshold in firmware or use endpoint /flush and set minutes");
142+
}
143+
else {
144+
res.print("Please specify amount of seconds in query parameter; pour_tea?seconds=10 e.g..");
145+
}
146+
}
147+
148+
void flush(Request &req, Response &res) {
149+
char minutes_char[64];
150+
req.query("minutes", minutes_char, 64);
151+
152+
if (strlen(minutes_char) != NULL){
153+
//release breaks
154+
digitalWrite(brakePin, LOW);
155+
156+
//set work duty for the motor, Duty is the amount of power it is getting from 0 to 256.
157+
analogWrite(pwmPin, 256);
158+
159+
int pouring_delay = atoi(minutes_char);
160+
delay(pouring_delay*1000*60); // convert miliseconds to seconds
161+
162+
//activate breaks
163+
digitalWrite(brakePin, HIGH);
164+
165+
//set work duty for the motor to 0 (off)
166+
analogWrite(pwmPin, 0);
167+
// Serial.println(req.JSON());
168+
res.print("Poured Tea in: ");
169+
res.print(pouring_delay);
170+
res.print(" minutes!");
171+
} else {
172+
res.print("Please specify amount of seconds in query parameter; flush?minutes=1 e.g..");
173+
}
174+
}
175+
176+
void setup() {
177+
178+
// define print serial port
179+
Serial.begin(9600);
180+
//define pins
181+
pinMode(directionPin, OUTPUT);
182+
pinMode(pwmPin, OUTPUT);
183+
pinMode(brakePin, OUTPUT);
184+
185+
// connect to WiFi
186+
connectToWiFi();
187+
188+
// Set endpoints
189+
app.post("/pour_tea", &pour_tea);
190+
app.post("/flush", &flush);
191+
app.get("/threshold", &get_threshold);
192+
app.post("/threshold", &set_threshold);
193+
194+
// setup Server
195+
server.begin();
196+
}
197+
198+
void loop() {
199+
WiFiClient client = server.available();
200+
201+
if (client.connected()) {
202+
app.process(&client);
203+
client.stop();
204+
}
205+
};

controller/tea_poor/test/README

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
This directory is intended for PlatformIO Test Runner and project tests.
3+
4+
Unit Testing is a software testing method by which individual units of
5+
source code, sets of one or more MCU program modules together with associated
6+
control data, usage procedures, and operating procedures, are tested to
7+
determine whether they are fit for use. Unit testing finds problems early
8+
in the development cycle.
9+
10+
More information about PlatformIO Unit Testing:
11+
- https://docs.platformio.org/en/latest/advanced/unit-testing/index.html
234 KB
Loading

0 commit comments

Comments
 (0)