diff --git a/README.md b/README.md index dce0416..ee08868 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,4 @@ -# ATTNode v3 Firmware (WiP) - -## Disclaimer - -THIS IS STILL WORK IN PROGRESS! +# ATTNode v3 Firmware ## Documentation @@ -10,17 +6,15 @@ THIS IS STILL WORK IN PROGRESS! ## Configuration and Programming -This is the Work in Progress Repository for ATTNode v3 compatible firmware. At the moment it supports LoRa communication using OTAA and a BME280 or SHT21 sensor, as well as deep sleep between measurements. +This is the Repository for ATTNode v3 compatible firmware. At the moment it supports LoRa communication using OTAA and a BME280 or SHT21 sensor, as well as deep sleep between measurements. -As there is no PlatformIO Support for the ATTiny3216 yet, it is (for now) developed using Arduino IDE and the [MegaTinyCore](https://github.com/SpenceKonde/megaTinyCore). You also need to set the correct Settings for programming the ATTiny3216 in ArduionIDE. Here is a screenshot of the settings I use: +The Firmware is developed using [PlatformIO](https://platformio.org/). At least Version 5.1.0 is needed for ATTiny3216 Support. -![ArduinoIDE Settings](ide_settings.png) +To Set the Fuses for Clock Speed, BOD Levels etc., use the "Set Fuses" Operation in PlatformIO. This has to be done once for a "fresh" Node or when the Board Config in PlatformIO was changed. Afterwards it is enough to use the normal "Upload" function for Code or config.h changes. -You also need to install the MCCI Arduino LMIC Library form the IDEs Library Manager or from https://github.com/mcci-catena/arduino-lmic +Before Programming Node, copy src/config.h.example to src/config.h and set the used sensor, LoRaWAN keys and other options as needed. -Before Compiling and Flashing make sure to copy config.h.example to config.h and set your LoRa OTAA Keys there. You can also set the Sending Interval and used Sensors there. - -Programming is done using a [MicroUPDI Programmer](https://github.com/MCUdude/microUPDI) - for other pogramming variants see the MegaTinyCore documentation. +Programming is done using a [MicroUPDI Programmer](https://github.com/MCUdude/microUPDI), settings in platformio.ini are set to use it. For other pogrammer options see the PlatformIO Documentation ## Configuring via Downlink diff --git a/ide_settings.png b/ide_settings.png deleted file mode 100644 index 1813615..0000000 Binary files a/ide_settings.png and /dev/null differ diff --git a/include/README b/include/README new file mode 100644 index 0000000..2bfdc2e --- /dev/null +++ b/include/README @@ -0,0 +1,38 @@ +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/firmware/debug.h b/include/debug.h similarity index 100% rename from firmware/debug.h rename to include/debug.h diff --git a/firmware/BME280.cpp b/lib/BME280/BME280.cpp similarity index 100% rename from firmware/BME280.cpp rename to lib/BME280/BME280.cpp diff --git a/firmware/BME280.h b/lib/BME280/BME280.h similarity index 100% rename from firmware/BME280.h rename to lib/BME280/BME280.h diff --git a/lib/README b/lib/README new file mode 100644 index 0000000..6debab1 --- /dev/null +++ b/lib/README @@ -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 +#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/lib/SG112A/SG112A.cpp b/lib/SG112A/SG112A.cpp new file mode 100644 index 0000000..b23a49e --- /dev/null +++ b/lib/SG112A/SG112A.cpp @@ -0,0 +1,18 @@ +#include +#include "SG112A.h" + +void GA112A(void) { + +} + +uint16_t getPPM(void) { + +} + +void SG112A::sendCmd(uint8_t *cmd, uint8_t len) { + +} + +uint16_t SG112A::crc16(uint8_t *cmd, uint8_t len){ + +} diff --git a/lib/SG112A/SG112A.h b/lib/SG112A/SG112A.h new file mode 100644 index 0000000..2c1a9c6 --- /dev/null +++ b/lib/SG112A/SG112A.h @@ -0,0 +1,13 @@ +#ifndef SG112A_H +#define SG112A_H + +class SG112A { + private: + void sendCmd(uint8_t *cmd, uint8_t len); + uint16_t crc16(uint8_t *cmd, uint8_t len); + public: + SG112A(void); + uint16_t getPPM(void); +}; + +#endif diff --git a/firmware/SHT21.cpp b/lib/SHT21/SHT21.cpp similarity index 100% rename from firmware/SHT21.cpp rename to lib/SHT21/SHT21.cpp diff --git a/firmware/SHT21.h b/lib/SHT21/SHT21.h similarity index 100% rename from firmware/SHT21.h rename to lib/SHT21/SHT21.h diff --git a/platformio.ini b/platformio.ini new file mode 100644 index 0000000..9bc3ed1 --- /dev/null +++ b/platformio.ini @@ -0,0 +1,41 @@ +; 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:ATtiny3216] +platform = atmelmegaavr +board = ATtiny3216 +framework = arduino + +# Board Config +board_build.f_cpu = 5000000L +board_hardware.oscillator = internal +board_hardware.bod = disabled + +# Debug Port Config +monitor_speed = 115200 + +# LMIC Config via Build Flags +build_flags = + -D CFG_eu868 + -D CFG_sx1276_radio + -D DISABLE_PING + -D DISABLE_BEACONS + -D ARDUINO_LMIC_PROJECT_CONFIG_H_SUPPRESS + +# Programmer Config (MicroUPDI) +upload_port = usb +upload_protocol = xplainedmini_updi +upload_flags = + -p$BOARD_MCU + -P$UPLOAD_PORT + -c$UPLOAD_PROTOCOL + +lib_deps = + mcci-catena/MCCI LoRaWAN LMIC library @ ^3.3.0 diff --git a/firmware/config.h.example b/src/config.h.example similarity index 81% rename from firmware/config.h.example rename to src/config.h.example index afb9634..9fc253f 100644 --- a/firmware/config.h.example +++ b/src/config.h.example @@ -17,13 +17,6 @@ // Actual Sleep Time is SLEEP_TIME*2*32 Seconds due to the 32s sleep intervals of the ATTiny3216 uint16_t sleep_time = 10; -// Specify TTN EU Bandplan and LoRa Chip for the LMIC as well as Disabling some unused functions -// See LMIC documentation / project_config.h for more options -#define CFG_eu868 1 -#define CFG_sx1276_radio 1 -#define DISABLE_PING -#define DISABLE_BEACONS - // Keys for OTAA Mode // APPEUI and DEVEUI from TTN, LSB! static const u1_t PROGMEM APPEUI[8]={ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; diff --git a/firmware/firmware.ino b/src/main.cpp similarity index 96% rename from firmware/firmware.ino rename to src/main.cpp index 6d0f94b..6710147 100644 --- a/firmware/firmware.ino +++ b/src/main.cpp @@ -1,4 +1,3 @@ - #include #include #include @@ -6,13 +5,12 @@ #include #include +#include +#include + // Keep Track of used EEPROM Addresses #define ADDR_SLP 0 // Sleep Interval, 2 Bytes -// Use the local config.h for LMIC Configuration -#define ARDUINO_LMIC_PROJECT_CONFIG_H config.h -#include -#include #include "config.h" #include "debug.h" @@ -34,12 +32,12 @@ void blink(uint8_t num) { #endif #ifdef HAS_BME280 -#include "BME280.h" +#include BME280 sensor; #endif #ifdef HAS_SHT21 -#include "SHT21.h" +#include SHT21 sensor; #endif @@ -54,6 +52,7 @@ void os_getDevKey (u1_t* buf) { memcpy_P(buf, APPKEY, 16); } static osjob_t sendjob; +void do_send(osjob_t* j); // Pin-Mapping for ATTNode v3 const lmic_pinmap lmic_pins = { @@ -214,7 +213,7 @@ void setup() DEBUG_PRINT("Initializing LMIC...") os_init(); LMIC_reset(); // Reset LMIC state and cancel all queued transmissions - LMIC_setClockError(MAX_CLOCK_ERROR * 1 / 100); // Compensate for Clock Skew + LMIC_setClockError(MAX_CLOCK_ERROR * 10 / 100); // Compensate for Clock Skew LMIC.dn2Dr = DR_SF9; // Downlink Band LMIC_setDrTxpow(DR_SF7, 14); // Default to SF7 DEBUG_PRINTLN("Done");