initial
This commit is contained in:
parent
62c63a51b1
commit
03c0b74a30
5
.gitignore
vendored
Normal file
5
.gitignore
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
.pio
|
||||
.vscode/.browse.c_cpp.db*
|
||||
.vscode/c_cpp_properties.json
|
||||
.vscode/launch.json
|
||||
.vscode/ipch
|
10
.vscode/extensions.json
vendored
Normal file
10
.vscode/extensions.json
vendored
Normal file
@ -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"
|
||||
]
|
||||
}
|
37
include/README
Normal file
37
include/README
Normal file
@ -0,0 +1,37 @@
|
||||
|
||||
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 convention is to give header files names that end with `.h'.
|
||||
|
||||
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
lib/README
Normal file
46
lib/README
Normal file
@ -0,0 +1,46 @@
|
||||
|
||||
This directory is intended for project specific (private) libraries.
|
||||
PlatformIO will compile them to static libraries and link into the executable file.
|
||||
|
||||
The source code of each library should be placed in a separate directory
|
||||
("lib/your_library_name/[Code]").
|
||||
|
||||
For example, see the structure of the following example libraries `Foo` and `Bar`:
|
||||
|
||||
|--lib
|
||||
| |
|
||||
| |--Bar
|
||||
| | |--docs
|
||||
| | |--examples
|
||||
| | |--src
|
||||
| | |- Bar.c
|
||||
| | |- Bar.h
|
||||
| | |- library.json (optional. for 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
|
||||
|
||||
Example contents of `src/main.c` using Foo and Bar:
|
||||
```
|
||||
#include <Foo.h>
|
||||
#include <Bar.h>
|
||||
|
||||
int main (void)
|
||||
{
|
||||
...
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
The PlatformIO Library Dependency Finder will find automatically dependent
|
||||
libraries by scanning project source files.
|
||||
|
||||
More information about PlatformIO Library Dependency Finder
|
||||
- https://docs.platformio.org/page/librarymanager/ldf.html
|
138
platformio.ini
Normal file
138
platformio.ini
Normal file
@ -0,0 +1,138 @@
|
||||
; 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:esp32-c3-devkitm-1]
|
||||
; platform = espressif32
|
||||
; board = esp32-c3-devkitm-1
|
||||
; framework = arduino
|
||||
|
||||
|
||||
[platformio]
|
||||
default_envs = test
|
||||
|
||||
|
||||
;CHANGE THE VERSION BELOW !!!!!!
|
||||
[program_customisation]
|
||||
version = "0.19.03" ; don't use letters, 2 digits in each field
|
||||
client = "papio"
|
||||
|
||||
[scripts_defaults]
|
||||
extra_scripts =
|
||||
; post:extra_scripts/output_bins.py
|
||||
; post:extra_scripts/erase_before_upload.py
|
||||
|
||||
[common]
|
||||
build_flags =
|
||||
'-DHOSTNAME="$PIOENV"'
|
||||
'-Os'
|
||||
'-D ZH_PROG_VERSION=${program_customisation.version}'
|
||||
'-D CLIENT=${program_customisation.client}'
|
||||
-DCORE_DEBUG_LEVEL=0
|
||||
; -DCORE_DEBUG_LEVEL=5
|
||||
-D CONFIG_ESP_COEX_SW_COEXIST_ENABLE
|
||||
; -D CONFIG_ESP_INT_WDT_TIMEOUT_MS=300
|
||||
; -D CONFIG_ESP_TASK_WDT_TIMEOUT_S=3
|
||||
|
||||
lib_deps =
|
||||
; ^1.2.3 means that any 1.x.x version is accpeted.
|
||||
; ~1.2.3 means that any 1.2.x version is accepted.
|
||||
; "@ ~" Accept only backwards compatible bug fixes
|
||||
|
||||
; common - needed SOMETIMES:
|
||||
FS
|
||||
SPIFFS
|
||||
Wire
|
||||
WiFi
|
||||
|
||||
; Project specific: some libs moved to /lib so local
|
||||
; arduino-libraries/ArduinoBLE @ ~1.3.7
|
||||
SPI
|
||||
; bodmer/TFT_eSPI @ ~2.5.43
|
||||
; pstolarz/OneWireNg @ ~0.13.3
|
||||
; robtillaart/ADS1X15 @ ~0.5.1
|
||||
|
||||
; OTA - FW update
|
||||
; esphome/ESPAsyncWebServer-esphome@^2.1.0
|
||||
; ottowinter/ESPAsyncTCP-esphome @ ^1.2.3
|
||||
Update
|
||||
|
||||
monitor_filters = time, colorize, esp32_exception_decoder
|
||||
platform = espressif32
|
||||
framework = arduino
|
||||
|
||||
; my common libraries
|
||||
lib_extra_dirs =
|
||||
; /Users/papio/3-Programming/02-Platformio/0-common-libs
|
||||
|
||||
; =========================================================================================================
|
||||
; CUSTOM board: ZH bare module OK, here are partition and pins
|
||||
; /Users/papio/.platformio/packages/framework-arduinoespressif32/variants/zh_esp32s3_bare_module
|
||||
; here is where the boards are described:
|
||||
|
||||
; using UART, with DARDUINO_USB_CDC_ON_BOOT=0
|
||||
; /Users/papio/.platformio/platforms/espressif32/boards/zh_esp32s3_bare_module.json
|
||||
|
||||
; using UART, with DARDUINO_USB_CDC_ON_BOOT=0 - same as above - linked
|
||||
; /Users/papio/.platformio/platforms/espressif32/boards/zh_esp32s3_bare_module-uart.json
|
||||
|
||||
; using USB OTG, with DARDUINO_USB_CDC_ON_BOOT=1
|
||||
; no need to have reset and gpio 0 exposed for programming - it does it automatically (like RTS/DTR)
|
||||
; /Users/papio/.platformio/platforms/espressif32/boards/zh_esp32s3_bare_module-usb-otg.json
|
||||
|
||||
|
||||
; [zh_esp32s3_bare_module]
|
||||
; board = zh_esp32s3_bare_module
|
||||
|
||||
; [zh_esp32s3_bare_module-uart]
|
||||
; board = zh_esp32s3_bare_module-uart
|
||||
|
||||
; [zh_esp32s3_bare_module-usbotg]
|
||||
; board = zh_esp32s3_bare_module-usb-otg
|
||||
; =========================================================================================================
|
||||
|
||||
|
||||
[esp32]
|
||||
board=esp32dev
|
||||
|
||||
[esp32c3]
|
||||
board=esp32-c3-devkitm-1
|
||||
|
||||
[wemoss3minilolin]
|
||||
board = lolin_s3_mini
|
||||
|
||||
[zh_esp32s3_bare_module-usbotg]
|
||||
board = zh_esp32s3_bare_module-usb-otg
|
||||
|
||||
[env]
|
||||
upload_speed = 921600
|
||||
monitor_speed = 115200
|
||||
extra_scripts = ${scripts_defaults.extra_scripts}
|
||||
monitor_port = /dev/cu.usbmodem2101
|
||||
upload_port = /dev/cu.usbmodem2101
|
||||
|
||||
[base]
|
||||
monitor_filters = ${common.monitor_filters}
|
||||
platform = ${common.platform}
|
||||
framework = ${common.framework}
|
||||
lib_deps = ${common.lib_deps}
|
||||
build_flags = ${common.build_flags}
|
||||
lib_extra_dirs = ${common.lib_extra_dirs}
|
||||
board_build.partitions = min_spiffs.csv ; not enough space on C3
|
||||
|
||||
; ********************* TEST boards definition start here *********************
|
||||
|
||||
[env:test]
|
||||
extends = base
|
||||
board = ${esp32c3.board}
|
||||
build_flags = ${base.build_flags}
|
||||
-D DEVICE_ID=13
|
||||
-DARDUINO_USB_MODE=1
|
||||
-DARDUINO_USB_CDC_ON_BOOT=1
|
||||
|
108
src/main.cpp
Normal file
108
src/main.cpp
Normal file
@ -0,0 +1,108 @@
|
||||
/*
|
||||
https://www.electronicssimplified.in/esp32/esp32-ble-server-and-client-with-arduino-a-complete-guide/
|
||||
https://www.programmingelectronics.com/esp32-ble-client/
|
||||
|
||||
*/
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <BLEDevice.h>
|
||||
#include <BLEServer.h>
|
||||
#include <BLEUtils.h>
|
||||
#include <BLE2902.h>
|
||||
|
||||
#define bleServerName "garage_000001_accu_0"
|
||||
#define SERVICE_UUID "0000fbb0-ABCD-1000-8000-00805f9b34fb"
|
||||
#define uS_TO_S_FACTOR 1000000ULL // auxuliary
|
||||
|
||||
RTC_DATA_ATTR int boot;
|
||||
|
||||
void do_esp_go_to_sleep()
|
||||
{
|
||||
esp_deep_sleep_start();
|
||||
}
|
||||
|
||||
|
||||
void hibernate(int final_sleeping_time_s)
|
||||
{
|
||||
esp_deep_sleep_disable_rom_logging();
|
||||
esp_sleep_pd_config(ESP_PD_DOMAIN_XTAL, ESP_PD_OPTION_OFF);
|
||||
esp_sleep_pd_config(ESP_PD_DOMAIN_RTC8M, ESP_PD_OPTION_OFF);
|
||||
esp_sleep_pd_config(ESP_PD_DOMAIN_VDDSDIO, ESP_PD_OPTION_OFF);
|
||||
esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_SLOW_MEM, ESP_PD_OPTION_OFF);
|
||||
esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_FAST_MEM, ESP_PD_OPTION_OFF);
|
||||
esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_OFF);
|
||||
|
||||
esp_sleep_enable_timer_wakeup(final_sleeping_time_s * uS_TO_S_FACTOR);
|
||||
do_esp_go_to_sleep();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
// delay(5000);
|
||||
// Serial.begin(115200);
|
||||
|
||||
boot++;
|
||||
pinMode(8, OUTPUT);
|
||||
digitalWrite(8, LOW);
|
||||
|
||||
// Create the BLE Device
|
||||
BLEDevice::init(bleServerName);
|
||||
// Create the BLE Server
|
||||
BLEServer *pServer = BLEDevice::createServer();
|
||||
// Create the BLE Service
|
||||
BLEService *BLEService = pServer->createService(SERVICE_UUID);
|
||||
// Start the service
|
||||
BLEService->start();
|
||||
|
||||
// 000180EACA108A78E36D0000E60A00005B00
|
||||
|
||||
// data x1: 5 digits or 4 and minus: -9999...99999 - milivolts
|
||||
// int x1 = random(9000,15000);
|
||||
// u_int32_t x1 = 35588;//random(-9999,99999);
|
||||
u_int32_t x1 = 12345;
|
||||
char x1char[6];
|
||||
snprintf(x1char,sizeof(x1char),"%5d",x1);
|
||||
|
||||
// data x2: 3 numbers or 2 and minus -99...999
|
||||
// int x2 = random(-99,999);
|
||||
int x2 = 123;
|
||||
char x2char[4];
|
||||
snprintf(x2char,sizeof(x2char),"%3d",x2);
|
||||
|
||||
// data x3: 4 numbers or 3 and minus -999...9999
|
||||
// int x3 = random(-999,9999);
|
||||
int x3 = 1234;
|
||||
char x3char[5];
|
||||
snprintf(x3char,sizeof(x3char),"%4d",x3);
|
||||
|
||||
// data x4: 4 numbers or 3 and minus -999...9999
|
||||
// int x4 = random(-999,9999);
|
||||
int x4 = 1234;
|
||||
// int x4 = boot;
|
||||
|
||||
char x4char[5];
|
||||
snprintf(x4char,sizeof(x4char),"%4d",x4);
|
||||
|
||||
char ms[36];
|
||||
snprintf(ms,sizeof(ms),"%s%s%s%s",x1char,x2char,x3char,x4char);
|
||||
|
||||
// Start advertising
|
||||
BLEAdvertising *pAdvertising2 = BLEDevice::getAdvertising();
|
||||
BLEAdvertisementData manufacturerdata = BLEAdvertisementData();
|
||||
manufacturerdata.setManufacturerData(ms);
|
||||
|
||||
pAdvertising2->setAdvertisementData(manufacturerdata);
|
||||
|
||||
pServer->getAdvertising()->start();
|
||||
|
||||
long sm2 = millis(); while(millis() < sm2 + 50) {};
|
||||
BLEDevice::getAdvertising()->stop();
|
||||
|
||||
digitalWrite(8, HIGH);
|
||||
// hibernate(random(2,7));
|
||||
hibernate(2);
|
||||
}
|
||||
|
||||
void loop() {}
|
11
test/README
Normal file
11
test/README
Normal file
@ -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…
Reference in New Issue
Block a user