Skip to content

Commit

Permalink
Merge pull request #25 from sensebox/feat/platformio
Browse files Browse the repository at this point in the history
PlatformIO
  • Loading branch information
felixerdy authored Jun 7, 2024
2 parents e7b9410 + 3b8c2a2 commit 7639421
Show file tree
Hide file tree
Showing 27 changed files with 2,373 additions and 1 deletion.
69 changes: 69 additions & 0 deletions .github/workflows/compile-sketches-platformio.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: PlatformIO CI

on:
push:
branches: [main]
tags: ["v*.*.*"]
pull_request:
branches:
- main

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.11"

- name: Install PlatformIO Core
run: pip install --upgrade platformio

- name: Build PlatformIO Project
run: pio run -d senseBox-bike-atrai-v2

- name: Create OTA update file
run: |
git clone https://github.com/arduino-libraries/ArduinoIoTCloud.git
pip install crccheck
cd ArduinoIoTCloud/extras/tools
python3 lzss.py --encode ${{ github.workspace }}/senseBox-bike-atrai-v2/.pio/build/sensebox_mcu_esp32s2/firmware.bin ${{ runner.temp }}/firmware.bin.lzss
python3 bin2ota.py ESP32 ${{ runner.temp }}/firmware.bin.lzss ${{ runner.temp }}/firmware.ota
mv ${{ runner.temp }}/firmware.ota ${{ github.workspace }}/senseBox-bike-atrai-v2/.pio/build/sensebox_mcu_esp32s2/senseBox-bike-atrai-v2.bin.ota
mv ${{ github.workspace }}/senseBox-bike-atrai-v2/.pio/build/sensebox_mcu_esp32s2/firmware.bin ${{ github.workspace }}/senseBox-bike-atrai-v2/.pio/build/sensebox_mcu_esp32s2/senseBox-bike-atrai-v2.bin
- name: Export binaries as artifacts
uses: actions/upload-artifact@v4
with:
name: senseBox-bike-atrai-v2-artifacts
path: ${{ github.workspace }}

release:
needs: build
runs-on: ubuntu-latest
steps:
- name: Download Firmware Files
uses: actions/download-artifact@v4
with:
path: release
- name: Release Firmware
uses: ncipollo/release-action@v1
if: startsWith(github.ref, 'refs/tags/')
with:
artifacts: "release/**/*.bin, release/**/*.ota"
allowUpdates: true
omitBodyDuringUpdate: true
token: ${{ secrets.GITHUB_TOKEN }}
3 changes: 2 additions & 1 deletion .github/workflows/compile-sketches.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ jobs:
platforms: |
- name: esp32:esp32
source-url: https://espressif.github.io/arduino-esp32/package_esp32_index.json
version: 2.0.17
sketch-paths: |
- ./senseBox-bike-atrai
- ./senseBox-bike-mcus2
Expand All @@ -43,7 +44,7 @@ jobs:
uses: actions/checkout@v4

# For more information: https://github.com/arduino/compile-sketches#readme
- name: Compile sketch
- name: "[Arduino CLI] Compile sketch"
uses: arduino/compile-sketches@v1
with:
fqbn: ${{ matrix.board.fqbn }}
Expand Down
5 changes: 5 additions & 0 deletions senseBox-bike-atrai-v2/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.pio
.vscode/.browse.c_cpp.db*
.vscode/c_cpp_properties.json
.vscode/launch.json
.vscode/ipch
10 changes: 10 additions & 0 deletions senseBox-bike-atrai-v2/.vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
// 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"
]
}
3 changes: 3 additions & 0 deletions senseBox-bike-atrai-v2/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"editor.defaultFormatter": "ms-vscode.cpptools"
}
39 changes: 39 additions & 0 deletions senseBox-bike-atrai-v2/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 senseBox-bike-atrai-v2/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 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
25 changes: 25 additions & 0 deletions senseBox-bike-atrai-v2/platformio.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
; 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:sensebox_mcu_esp32s2]
platform = espressif32
board = sensebox_mcu_esp32s2
platform_packages = platformio/framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git#2.0.17
framework = arduino
lib_deps =
adafruit/Adafruit SSD1306 @ ^2.5.10
adafruit/Adafruit HDC1000 Library@^2.0.2
sensirion/sensirion-sps@^1.1.2
https://github.com/felixerdy/QRCodeGenerator.git
adafruit/Adafruit MAX1704X@^1.0.3
stm32duino/STM32duino VL53L8CX@^1.0.3
adafruit/Adafruit MPU6050@^2.2.6
sensebox/SenseBoxBLE@^1.1.0
adafruit/Adafruit NeoPixel@^1.12.2
91 changes: 91 additions & 0 deletions senseBox-bike-atrai-v2/src/ble/BLEModule.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#include "BLEModule.h"

// void (*BLEModule::receiveCallback)(BLEDevice, BLECharacteristic) = nullptr;

BLEModule::BLEModule()
{
// service = nullptr;
bleName = "";
}

bool BLEModule::begin()
{
SenseBoxBLE::start("senseBox-BLE");
delay(500);
bleName = "senseBox:bike [" + SenseBoxBLE::getMCUId() + "]";
SenseBoxBLE::setName(bleName);

delay(200);
SenseBoxBLE::addService("CF06A218F68EE0BEAD048EBC1EB0BC84");

xTaskCreate(bleTask, "bleTask", 1024, NULL, 1, NULL);

return true;
}

String BLEModule::getBLEName()
{
return bleName;
}

const char **BLEModule::getBLEConnectionString()
{
String bleId = "[" + SenseBoxBLE::getMCUId() + "]";
String bleIdBegin = bleId.substring(0, bleId.length() / 2);
String bleIdEnd = bleId.substring(bleId.length() / 2);
const char *MESSAGE_CONFIGURE_WIFI[] = {
"senseBox",
"bike",
bleIdBegin.c_str(),
bleIdEnd.c_str()};
return MESSAGE_CONFIGURE_WIFI;
}

int BLEModule::createCharacteristic(const char *uuid)
{
return SenseBoxBLE::addCharacteristic(uuid);
}

bool BLEModule::writeBLE(int characteristicId, float value)
{
return SenseBoxBLE::write(characteristicId, value);
}

bool BLEModule::writeBLE(int characteristicId, float value, float value2)
{
return SenseBoxBLE::write(characteristicId, value, value2);
}

bool BLEModule::writeBLE(int characteristicId, float value, float value2, float value3)
{
return SenseBoxBLE::write(characteristicId, value, value2, value3);
}

bool BLEModule::writeBLE(int characteristicId, float value, float value2, float value3, float value4)
{
return SenseBoxBLE::write(characteristicId, value, value2, value3, value4);
}

bool BLEModule::writeBLE(int characteristicId, float value, float value2, float value3, float value4, float value5)
{
return SenseBoxBLE::write(characteristicId, value, value2, value3, value4, value5);
}

// void BLEModule::setReceiveCallback(void (*callback)(BLEDevice, BLECharacteristic)) {
// receiveCallback = callback;
// }

// void BLEModule::onReceive(BLEDevice central, BLECharacteristic characteristic) {
// if (receiveCallback) {
// receiveCallback(central, characteristic);
// }
// }

void BLEModule::bleTask(void *pvParameters)
{
while (true)
{
SenseBoxBLE::poll();
vTaskDelay(pdMS_TO_TICKS(5));
}
}
43 changes: 43 additions & 0 deletions senseBox-bike-atrai-v2/src/ble/BLEModule.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#ifndef BLE_MODULE_H
#define BLE_MODULE_H

#include <Arduino.h>
#include <SenseBoxBLE.h>

class BLEModule
{
public:
BLEModule();

// Initialize the BLE module
bool begin();

// Get the BLE module ID
String getBLEName();

const char** getBLEConnectionString();

// Create a BLE characteristic
static int createCharacteristic(const char *uuid);

static bool writeBLE(int characteristicId, float value);
static bool writeBLE(int characteristicId, float value, float value2);
static bool writeBLE(int characteristicId, float value, float value2, float value3);
static bool writeBLE(int characteristicId, float value, float value2, float value3, float value4);
static bool writeBLE(int characteristicId, float value, float value2, float value3, float value4, float value5);

// Set callback for receiving data
// void setReceiveCallback(void (*callback)(BLEDevice, BLECharacteristic));

// Task function for polling BLE
static void bleTask(void *pvParameters);

private:
// BLEService* service;
String bleName;

// static void onReceive(BLEDevice central, BLECharacteristic characteristic);
// static void (*receiveCallback)(BLEDevice, BLECharacteristic);
};

#endif // BLE_MODULE_H
Loading

0 comments on commit 7639421

Please sign in to comment.