From b119a84ff5c0b8ccf8ca2a467065a4637ec78515 Mon Sep 17 00:00:00 2001 From: Lemonochrme Date: Wed, 18 Dec 2024 08:48:53 +0100 Subject: [PATCH] Cleaned previous embedded file as microchip chip doesn't work --- embedded/.gitignore | 5 -- embedded/.vscode/extensions.json | 10 --- embedded/include/README | 39 --------- embedded/lib/README | 46 ----------- embedded/lib/sensor/sensor.cpp | 25 ------ embedded/lib/sensor/sensor.hpp | 19 ----- embedded/platformio.ini | 20 ----- embedded/src/main.cpp | 132 ------------------------------- embedded/src/save_mit_app | 60 -------------- embedded/test/README | 11 --- 10 files changed, 367 deletions(-) delete mode 100644 embedded/.gitignore delete mode 100644 embedded/.vscode/extensions.json delete mode 100644 embedded/include/README delete mode 100644 embedded/lib/README delete mode 100644 embedded/lib/sensor/sensor.cpp delete mode 100644 embedded/lib/sensor/sensor.hpp delete mode 100644 embedded/platformio.ini delete mode 100644 embedded/src/main.cpp delete mode 100644 embedded/src/save_mit_app delete mode 100644 embedded/test/README diff --git a/embedded/.gitignore b/embedded/.gitignore deleted file mode 100644 index 89cc49c..0000000 --- a/embedded/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -.pio -.vscode/.browse.c_cpp.db* -.vscode/c_cpp_properties.json -.vscode/launch.json -.vscode/ipch diff --git a/embedded/.vscode/extensions.json b/embedded/.vscode/extensions.json deleted file mode 100644 index 080e70d..0000000 --- a/embedded/.vscode/extensions.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - // See http://go.microsoft.com/fwlink/?LinkId=827846 - // for the documentation about the extensions.json format - "recommendations": [ - "platformio.platformio-ide" - ], - "unwantedRecommendations": [ - "ms-vscode.cpptools-extension-pack" - ] -} diff --git a/embedded/include/README b/embedded/include/README deleted file mode 100644 index 194dcd4..0000000 --- a/embedded/include/README +++ /dev/null @@ -1,39 +0,0 @@ - -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 diff --git a/embedded/lib/README b/embedded/lib/README deleted file mode 100644 index 2593a33..0000000 --- a/embedded/lib/README +++ /dev/null @@ -1,46 +0,0 @@ - -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 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 -#include - -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 diff --git a/embedded/lib/sensor/sensor.cpp b/embedded/lib/sensor/sensor.cpp deleted file mode 100644 index 9660849..0000000 --- a/embedded/lib/sensor/sensor.cpp +++ /dev/null @@ -1,25 +0,0 @@ -#include "sensor.hpp" -#include - -Sensor::Sensor() -{} - -void Sensor::init(const uint8_t pin) -{ - _pin = pin; - pinMode(_pin, INPUT); - digitalWrite(_pin, HIGH); -} - -float Sensor::get_analog() -{ - return (static_cast(analogRead(_pin))/(1<<12))*3.3f; -} - -// Normally should be 5V, but the ADC can only see up to 3.3 on 12 bits -float Sensor::get_RSR0() -{ - float sensor_volt=(static_cast(analogRead(_pin))/(1<<12))*3.3f; - float RS_gas = (3.3-sensor_volt)/sensor_volt; - return RS_gas/R0; -} \ No newline at end of file diff --git a/embedded/lib/sensor/sensor.hpp b/embedded/lib/sensor/sensor.hpp deleted file mode 100644 index d4d356a..0000000 --- a/embedded/lib/sensor/sensor.hpp +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef HEADER_SENSOR -#define HEADER_SENSOR - -#include - -constexpr uint8_t SENSOR_PIN = 34; -constexpr float R0 = 0.8; - -class Sensor { -public: - Sensor(); - void init(const uint8_t pin); - float get_analog(); - float get_RSR0(); -private: - uint8_t _pin; -}; - -#endif // HEADER_SENSOR \ No newline at end of file diff --git a/embedded/platformio.ini b/embedded/platformio.ini deleted file mode 100644 index 4d47f4b..0000000 --- a/embedded/platformio.ini +++ /dev/null @@ -1,20 +0,0 @@ -; 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:esp32dev] -platform = espressif32 -board = esp32dev -monitor_speed = 115200 -framework = arduino -lib_deps = - adafruit/Adafruit SSD1306@^2.5.13 - adafruit/Adafruit GFX Library@^1.11.11 - mbed-seeed/BluetoothSerial@0.0.0+sha.f56002898ee8 - adafruit/Adafruit BusIO@^1.16.2 diff --git a/embedded/src/main.cpp b/embedded/src/main.cpp deleted file mode 100644 index b3d7fb6..0000000 --- a/embedded/src/main.cpp +++ /dev/null @@ -1,132 +0,0 @@ -#include -#include -#include -#include -#include - -#include "sensor.hpp" - -#define SCREEN_WIDTH 128 -#define SCREEN_HEIGHT 64 - -// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins) -Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1); - -// RN2483Serial using RX2 and TX2 -HardwareSerial RN2483Serial(2); - -Sensor gaz_sensor; - -void printSSD1306(String text) { - display.clearDisplay(); - display.setCursor(0, 0); - display.println(text); - display.display(); -} - -void Init_SSD1306() { - // SSD1306 initialization - if(!display.begin(0x3C, 0x3C)) { // Address 0x3C for 128x64 - for(;;); - } - display.display(); - delay(2000); // Pause for 2 seconds - - display.clearDisplay(); - display.setTextSize(1); // Normal 1:1 pixel scale - display.setTextColor(SSD1306_WHITE); // Draw white text - display.setCursor(0, 0); // Start at top-left corner - - display.println("SSD1306 Oled Initialized!"); - display.display(); - delay(1000); -} - -void test_RN2483A() { - // Send a command to the RN2483A module - RN2483Serial.println("sys get ver"); - - // Wait for a response - delay(1000); - - // Read the response from the RN2483A module - while (RN2483Serial.available()) { - String response = RN2483Serial.readString(); - printSSD1306("RN2483A Response:"); - Serial.println(response); - printSSD1306(response); - } -} - -void initGateway() { - String devEUI = "9a0698b4e20d4d2f"; - String joinEUI = "53760ec38137bbf8"; - String appKey = "4f30040e6b6f1a4f6a0ed332fc6f7ae7"; - - RN2483Serial.println("mac set deveui " + devEUI); - delay(100); - RN2483Serial.println("mac set appeui " + joinEUI); - delay(100); - RN2483Serial.println("mac set appkey " + appKey); - delay(100); - RN2483Serial.println("mac set pwridx 5"); - delay(100); - RN2483Serial.println("mac join otaa"); - - delay(5000); - - if (RN2483Serial.available()) { - String response = RN2483Serial.readString(); - Serial.println("Join Response: " + response); - printSSD1306("Join: " + response); - - if (response.indexOf("accepted") >= 0) { - Serial.println("Join accepted"); - printSSD1306("Join accepted"); - } else { - Serial.println("Join failed"); - printSSD1306("Join failed"); - } - } -} - -void sendToGateway() { - // Send Hello : 48656c6c6f in hex - RN2483Serial.println("mac tx uncnf 1 48656c6c6f"); - delay(1000); - - while (RN2483Serial.available()) { - String txResponse = RN2483Serial.readString(); - Serial.println("TX Response: " + txResponse); - printSSD1306("TX Response: " + txResponse); - } -} - - -void setup() { - Serial.begin(115200); - - // Initialize RN2483A Serial communication - RN2483Serial.begin(57600); - Serial.begin(115200); - - // Initialize SSD1306 - Init_SSD1306(); - delay(5000); - - // Initialize Gateway from LoRa - initGateway(); - - // Initialize Sensor - gaz_sensor.init(SENSOR_PIN); -} - -void loop() { - // test_RN2483A(); - // Serial.print("Value from sensor: "); - // Serial.println(gaz_sensor.get_value()); - // delay(1000); - - // Test communication to gateway - sendToGateway(); -} diff --git a/embedded/src/save_mit_app b/embedded/src/save_mit_app deleted file mode 100644 index ff5a1e5..0000000 --- a/embedded/src/save_mit_app +++ /dev/null @@ -1,60 +0,0 @@ -#include "Arduino.h" -#include "BluetoothSerial.h" -#include -#include - -BluetoothSerial SerialBT; - -const int LED_BUILTIN = 2; - -String receivedMessage = ""; - -void processBluetoothMessage(String message); - -void setup() { - pinMode(LED_BUILTIN, OUTPUT); - digitalWrite(LED_BUILTIN, HIGH); - - Serial.begin(115200); - Serial.println("Starting Bluetooth..."); - - if (!SerialBT.begin("ESP32 Yohan et Robin")) { - Serial.println("Error on starting Bluetooth"); - while (1); - } - - Serial.println("Bluetooth started, waitint for connections..."); -} - -void loop() { - if (SerialBT.available()) { - char receivedChar = SerialBT.read(); - - receivedMessage += receivedChar; - Serial.print("Current message: "); - Serial.println(receivedMessage); - - if (receivedMessage.endsWith("o")) { - processBluetoothMessage("ON"); - receivedMessage = ""; - } else if (receivedMessage.endsWith("f")) { - processBluetoothMessage("OFF"); - receivedMessage = ""; - } - } -} - -void processBluetoothMessage(String message) { - message.trim(); - Serial.println("Received: " + message); - - if (message.equalsIgnoreCase("ON")) { - digitalWrite(LED_BUILTIN, HIGH); - Serial.println("Turning LED ON"); - } else if (message.equalsIgnoreCase("OFF")) { - digitalWrite(LED_BUILTIN, LOW); - Serial.println("Turning LED OFF"); - } else { - Serial.println("Invalid command received"); - } -} diff --git a/embedded/test/README b/embedded/test/README deleted file mode 100644 index 9b1e87b..0000000 --- a/embedded/test/README +++ /dev/null @@ -1,11 +0,0 @@ - -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