From 2fe26ef34b32372f89600d5814eeeb6c241224f8 Mon Sep 17 00:00:00 2001 From: Tobias Hopp Date: Tue, 17 Jan 2023 22:57:51 +0100 Subject: [PATCH] Update Took 10 minutes --- arduino/itender/.theia/launch.json | 8 ++++++ arduino/itender/data/tare.ino | 0 arduino/itender/itender.ino | 20 +++++++++++--- arduino/itender/tare.ino | 43 ++++++++++++++++++++++++++++++ doc/installPi.sh | 4 +++ src/database/Database.ts | 15 ++++------- 6 files changed, 76 insertions(+), 14 deletions(-) create mode 100644 arduino/itender/.theia/launch.json create mode 100644 arduino/itender/data/tare.ino create mode 100644 arduino/itender/tare.ino diff --git a/arduino/itender/.theia/launch.json b/arduino/itender/.theia/launch.json new file mode 100644 index 0000000..9a49ac9 --- /dev/null +++ b/arduino/itender/.theia/launch.json @@ -0,0 +1,8 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + "version": "0.2.0", + "configurations": [ + + ] +} diff --git a/arduino/itender/data/tare.ino b/arduino/itender/data/tare.ino new file mode 100644 index 0000000..e69de29 diff --git a/arduino/itender/itender.ino b/arduino/itender/itender.ino index eeee9d2..7f19d5e 100644 --- a/arduino/itender/itender.ino +++ b/arduino/itender/itender.ino @@ -2,13 +2,25 @@ * Official proxy code for iTender GPIO Communication **/ +#include "HX711.h" +#include + +DynamicJsonDocument<200> doc; void setup() { - // put your setup code here, to run once: - Serial.begin(9600); + Serial.begin(9600); + + while (!Serial) continue; + + } + + void loop() { - // put your main code here, to run repeatedly: - + if( Serial.available() > 0 ) + { + String data = Serial.readString(); + + } } diff --git a/arduino/itender/tare.ino b/arduino/itender/tare.ino new file mode 100644 index 0000000..8b497d5 --- /dev/null +++ b/arduino/itender/tare.ino @@ -0,0 +1,43 @@ +/** + +#include "HX711.h" + +const int LOADCELL_DOUT_PIN = 2; +const int LOADCELL_SCK_PIN = 3; + +HX711 scale; + +int minus = 0; + +void setup() { + // put your setup code here, to run once: + Serial.begin(9600); + delay(1000); + Serial.println("TARE"); + + scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN); + scale.set_scale(429.6159259259259); + scale.tare(); + + delay(1000); + minus=abs(scale.get_units(5)); + // scale.set_scale(); + // scale.tare(); + // Serial.println("TARE OK - PLACE WEIGHT"); + //delay(5000); +} + +int len = 0; +long sum = 0; + +void loop() { + if (scale.is_ready()) { + long data = scale.get_units(5) + minus; + Serial.println(data); + + } + +} + + +**/ diff --git a/doc/installPi.sh b/doc/installPi.sh index 0cef1bf..5743519 100644 --- a/doc/installPi.sh +++ b/doc/installPi.sh @@ -58,6 +58,10 @@ sudo -u itender mkdir -p /home/itender/bin sudo -u itender sh -c 'curl -fsSL https://raw.githubusercontent.com/arduino/arduino-cli/master/install.sh | BINDIR=/home/itender/bin/ sh' sudo -u itender /home/itender/bin/arduino-cli config init sudo -u itender /home/itender/bin/arduino-cli core update-index || true +sudo -u itender /home/itender/bin/arduino-cli lib search ArduinoJson || true +sudo -u itender /home/itender/bin/arduino-cli lib install ArduinoJson || true + + echo "Installing autostart..." # Autostart diff --git a/src/database/Database.ts b/src/database/Database.ts index d6ed6e7..10f3a19 100644 --- a/src/database/Database.ts +++ b/src/database/Database.ts @@ -4,30 +4,25 @@ import Ingredient from "./Ingredient"; import Drink from "./Drink"; import Container from "./Container"; +// create a namespace for logging const log = debug("itender:server"); export class Database { + // method to connect to the database public static connect(): Promise { return new Promise(async (resolve, reject) => { try { + //connect to mongodb using mongoose await Mongoose.connect("mongodb://127.0.0.1:27017/iTender?retryWrites=true"); log("Connected to Database"); - /*if (Mongoose.connection.readyState == Mongoose.ConnectionStates.connected) { - resolve(); - } else { - reject("Can't connect to database"); - }*/ - - // Preload schemes + // Preload the schema for Ingredient, Drink and Container Ingredient.find(); Drink.find(); Container.find(); - resolve(); } catch (e) { reject("Exception whilst connecting to Database " + e); } - }); } -} \ No newline at end of file +}