Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
psmgeelen committed Dec 23, 2023
0 parents commit a3b7171
Show file tree
Hide file tree
Showing 12 changed files with 357 additions and 0 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/platformio.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: PlatformIO CI

on: [push]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/cache@v3
with:
path: |
~/.cache/pip
~/.platformio/.cache
key: ${{ runner.os }}-pio
- uses: actions/setup-python@v4
with:
python-version: "3.9"
- name: Install PlatformIO Core
run: pip install --upgrade platformio

- name: Build PlatformIO Project
working-directory: ./controller/tea_poor
run: pio run
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
controller/tea_poor/.pio
**/.vscode/**
.idea
1 change: 1 addition & 0 deletions ReadMe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Project Tea
9 changes: 9 additions & 0 deletions UNLICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
This is free and unencumbered software released into the public domain.

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.

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.

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.

For more information, please refer to <http://unlicense.org/>
39 changes: 39 additions & 0 deletions controller/tea_poor/include/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

This directory is intended for project header files.

A header file is a file containing C declarations and macro definitions
to be shared between several project source files. You request the use of a
header file in your project source file (C, C++, etc) located in `src` folder
by including it, with the C preprocessing directive `#include'.

```src/main.c

#include "header.h"

int main (void)
{
...
}
```

Including a header file produces the same results as copying the header file
into each source file that needs it. Such copying would be time-consuming
and error-prone. With a header file, the related declarations appear
in only one place. If they need to be changed, they can be changed in one
place, and programs that include the header file will automatically use the
new version when next recompiled. The header file eliminates the labor of
finding and changing all the copies as well as the risk that a failure to
find one copy will result in inconsistencies within a program.

In C, the usual convention is to give header files names that end with `.h'.
It is most portable to use only letters, digits, dashes, and underscores in
header file names, and at most one dot.

Read more about using header files in official GCC documentation:

* Include Syntax
* Include Operation
* Once-Only Headers
* Computed Includes

https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html
46 changes: 46 additions & 0 deletions controller/tea_poor/lib/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@

This directory is intended for project specific (private) libraries.
PlatformIO will compile them to static libraries and link into executable file.

The source code of each library should be placed in a an own separate directory
("lib/your_library_name/[here are source files]").

For example, see a structure of the following two libraries `Foo` and `Bar`:

|--lib
| |
| |--Bar
| | |--docs
| | |--examples
| | |--src
| | |- Bar.c
| | |- Bar.h
| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
| |
| |--Foo
| | |- Foo.c
| | |- Foo.h
| |
| |- README --> THIS FILE
|
|- platformio.ini
|--src
|- main.c

and a contents of `src/main.c`:
```
#include <Foo.h>
#include <Bar.h>

int main (void)
{
...
}

```

PlatformIO Library Dependency Finder will find automatically dependent
libraries scanning project source files.

More information about PlatformIO Library Dependency Finder
- https://docs.platformio.org/page/librarymanager/ldf.html
17 changes: 17 additions & 0 deletions controller/tea_poor/platformio.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html

[env:uno_r4_wifi]
platform = renesas-ra
board = uno_r4_wifi
framework = arduino
lib_deps =
bblanchon/ArduinoJson@^6.21.4
lasselukkari/aWOT@^3.5.0
205 changes: 205 additions & 0 deletions controller/tea_poor/src/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
#include <Arduino.h>
#include <ArduinoJson.h>
#include <WiFiS3.h>
#include <aWOT.h>

// setting up WiFi
const char *SSID = "MyWiFiNetwork";
const char *PWD = "VerySecurePassword";

// Setting up Motorcontroller
int directionPin = 12;
int pwmPin = 3;
int brakePin = 9;

// minimalistic webserver
WiFiServer server(80);
Application app;

// Start value Threshold for pouring
int threshold_pour = 10;

void printMacAddress(byte mac[]) {
for (int i = 0; i < 6; i++) {
if (i > 0) {
Serial.print(":");
}
if (mac[i] < 16) {
Serial.print("0");
}
Serial.print(mac[i], HEX);
}
Serial.println();
}


void printCurrentNet() {
// print the SSID of the network you're attached to:
Serial.print("SSID: ");
Serial.println(WiFi.SSID());

// print the MAC address of the router you're attached to:
byte bssid[6];
WiFi.BSSID(bssid);
Serial.print("BSSID: ");
printMacAddress(bssid);

// print the received signal strength:
long rssi = WiFi.RSSI();
Serial.print("signal strength (RSSI):");
Serial.println(rssi);

// print the encryption type:
byte encryption = WiFi.encryptionType();
Serial.print("Encryption Type:");
Serial.println(encryption, HEX);
Serial.println();
}


void connectToWiFi() {

if (WiFi.status() == WL_NO_MODULE) {
Serial.println("Communication with WiFi module failed!");
// block further activity
while(true);
}

// info about your adapter
String firmware_version = WiFi.firmwareVersion();

Serial.print("WiFi Firmware Version: ");
Serial.println(firmware_version);
if ( firmware_version < WIFI_FIRMWARE_LATEST_VERSION) {
Serial.print("Latest available version: ");
Serial.println(WIFI_FIRMWARE_LATEST_VERSION);
Serial.println("Please upgrade your firmware.");
}


Serial.print("Connecting to ");
Serial.println(SSID);

WiFi.begin(SSID, PWD);

while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(500);
// we can even make the ESP32 to sleep
}

Serial.print("Connected. IP: ");
Serial.println(WiFi.localIP());
printCurrentNet();
}



void set_threshold(Request &req, Response &res) {
char seconds_char[64];
req.query("seconds", seconds_char, 64);

if (strlen(seconds_char) != NULL){
threshold_pour = atoi(seconds_char);
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: ");
res.print(threshold_pour);
} else {
res.print("Please specify amount of seconds in query parameter; threshold?seconds=10 e.g..");
}
}

void get_threshold(Request &req, Response &res) {
res.print("The threshold is: ");
res.print(threshold_pour);
res.print(" seconds.");
}

void pour_tea(Request &req, Response &res) {
char seconds_char[64];
req.query("seconds", seconds_char, 64);
int pouring_delay = atoi(seconds_char);

if (strlen(seconds_char) != NULL && pouring_delay <= threshold_pour ){
//release breaks
digitalWrite(brakePin, LOW);

//set work duty for the motor, Duty is the amount of power it is getting from 0 to 256.
analogWrite(pwmPin, 256);

delay(pouring_delay*1000); // convert miliseconds to seconds

//activate breaks
digitalWrite(brakePin, HIGH);

//set work duty for the motor to 0 (off)
analogWrite(pwmPin, 0);
// Serial.println(req.JSON());
res.print("Poured Tea in: ");
res.print(pouring_delay);
res.print(" seconds!");
} else if (pouring_delay > threshold_pour) {
res.print("Exceeded safety threshold for pouring. Change threshold in firmware or use endpoint /flush and set minutes");
}
else {
res.print("Please specify amount of seconds in query parameter; pour_tea?seconds=10 e.g..");
}
}

void flush(Request &req, Response &res) {
char minutes_char[64];
req.query("minutes", minutes_char, 64);

if (strlen(minutes_char) != NULL){
//release breaks
digitalWrite(brakePin, LOW);

//set work duty for the motor, Duty is the amount of power it is getting from 0 to 256.
analogWrite(pwmPin, 256);

int pouring_delay = atoi(minutes_char);
delay(pouring_delay*1000*60); // convert miliseconds to seconds

//activate breaks
digitalWrite(brakePin, HIGH);

//set work duty for the motor to 0 (off)
analogWrite(pwmPin, 0);
// Serial.println(req.JSON());
res.print("Poured Tea in: ");
res.print(pouring_delay);
res.print(" minutes!");
} else {
res.print("Please specify amount of seconds in query parameter; flush?minutes=1 e.g..");
}
}

void setup() {

// define print serial port
Serial.begin(9600);
//define pins
pinMode(directionPin, OUTPUT);
pinMode(pwmPin, OUTPUT);
pinMode(brakePin, OUTPUT);

// connect to WiFi
connectToWiFi();

// Set endpoints
app.post("/pour_tea", &pour_tea);
app.post("/flush", &flush);
app.get("/threshold", &get_threshold);
app.post("/threshold", &set_threshold);

// setup Server
server.begin();
}

void loop() {
WiFiClient client = server.available();

if (client.connected()) {
app.process(&client);
client.stop();
}
};
11 changes: 11 additions & 0 deletions controller/tea_poor/test/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

This directory is intended for PlatformIO Test Runner and project tests.

Unit Testing is a software testing method by which individual units of
source code, sets of one or more MCU program modules together with associated
control data, usage procedures, and operating procedures, are tested to
determine whether they are fit for use. Unit testing finds problems early
in the development cycle.

More information about PlatformIO Unit Testing:
- https://docs.platformio.org/en/latest/advanced/unit-testing/index.html
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions enclosure/Instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# TBA

0 comments on commit a3b7171

Please sign in to comment.