first commit
This commit is contained in:
commit
6c2c6bdb80
57
.clang-format
Normal file
57
.clang-format
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
---
|
||||||
|
BasedOnStyle: Mozilla
|
||||||
|
AccessModifierOffset: '-4'
|
||||||
|
AlignAfterOpenBracket: Align
|
||||||
|
AlignConsecutiveAssignments: 'true'
|
||||||
|
AlignConsecutiveDeclarations: 'true'
|
||||||
|
AlignOperands: 'true'
|
||||||
|
AlignTrailingComments: 'true'
|
||||||
|
AllowAllParametersOfDeclarationOnNextLine: 'true'
|
||||||
|
AllowShortBlocksOnASingleLine: 'true'
|
||||||
|
AllowShortCaseLabelsOnASingleLine: 'false'
|
||||||
|
AllowShortFunctionsOnASingleLine: Empty
|
||||||
|
AllowShortLoopsOnASingleLine: 'false'
|
||||||
|
AlwaysBreakAfterDefinitionReturnType: None
|
||||||
|
AlwaysBreakAfterReturnType: None
|
||||||
|
BreakBeforeBinaryOperators: All
|
||||||
|
BreakBeforeBraces: Allman
|
||||||
|
BreakBeforeTernaryOperators: 'true'
|
||||||
|
BreakConstructorInitializers: AfterColon
|
||||||
|
BreakStringLiterals: 'false'
|
||||||
|
ColumnLimit: '100'
|
||||||
|
ConstructorInitializerAllOnOneLineOrOnePerLine: 'false'
|
||||||
|
ConstructorInitializerIndentWidth: '0'
|
||||||
|
ContinuationIndentWidth: '4'
|
||||||
|
Cpp11BracedListStyle: 'false'
|
||||||
|
DerivePointerAlignment: 'false'
|
||||||
|
DisableFormat: 'false'
|
||||||
|
ExperimentalAutoDetectBinPacking: 'true'
|
||||||
|
IndentCaseLabels: 'true'
|
||||||
|
IndentWidth: '4'
|
||||||
|
IndentWrappedFunctionNames: 'false'
|
||||||
|
JavaScriptQuotes: Single
|
||||||
|
KeepEmptyLinesAtTheStartOfBlocks: 'false'
|
||||||
|
Language: Cpp
|
||||||
|
MaxEmptyLinesToKeep: '2'
|
||||||
|
NamespaceIndentation: None
|
||||||
|
ObjCBlockIndentWidth: '4'
|
||||||
|
ObjCSpaceAfterProperty: 'false'
|
||||||
|
ObjCSpaceBeforeProtocolList: 'false'
|
||||||
|
PointerAlignment: Left
|
||||||
|
ReflowComments: 'true'
|
||||||
|
SortIncludes: 'false'
|
||||||
|
SpaceAfterCStyleCast: 'true'
|
||||||
|
SpaceBeforeAssignmentOperators: 'true'
|
||||||
|
SpaceBeforeParens: ControlStatements
|
||||||
|
SpaceInEmptyParentheses: 'false'
|
||||||
|
SpacesBeforeTrailingComments: '2'
|
||||||
|
SpacesInAngles: 'false'
|
||||||
|
SpacesInCStyleCastParentheses: 'false'
|
||||||
|
SpacesInContainerLiterals: 'false'
|
||||||
|
SpacesInParentheses: 'false'
|
||||||
|
SpacesInSquareBrackets: 'false'
|
||||||
|
Standard: Cpp11
|
||||||
|
TabWidth: '4'
|
||||||
|
UseTab: Always
|
||||||
|
|
||||||
|
...
|
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
|
102
include/config.h
Normal file
102
include/config.h
Normal file
@ -0,0 +1,102 @@
|
|||||||
|
#include <Arduino.h>
|
||||||
|
|
||||||
|
// Whether the given script is using encryption or not,
|
||||||
|
// generally recommended as it increases security (communication with the server is not in clear
|
||||||
|
// text anymore), it does come with an overhead tough as having an encrypted session requires a lot
|
||||||
|
// of memory, which might not be avaialable on lower end devices.
|
||||||
|
#define ENCRYPTED false
|
||||||
|
|
||||||
|
// While we wait for Feather ESP32 V2 to get added to the Espressif BSP,
|
||||||
|
// we have to select PICO D4 and UNCOMMENT this line!
|
||||||
|
#define ADAFRUIT_FEATHER_ESP32_V2
|
||||||
|
|
||||||
|
// Enables the ThingsBoard class to be fully dynamic instead of requiring template arguments to
|
||||||
|
// statically allocate memory. If enabled the program might be slightly slower and all the memory
|
||||||
|
// will be placed onto the heap instead of the stack.
|
||||||
|
// #define THINGSBOARD_ENABLE_DYNAMIC 1
|
||||||
|
|
||||||
|
// If the THINGSBOARD_ENABLE_DYNAMIC 1 setting causes this error log message to appear [TB] Unable
|
||||||
|
// to de-serialize received json data with error (DeserializationError::NoMemory). Simply add this
|
||||||
|
// configuration line as well.
|
||||||
|
// #define THINGSBOARD_ENABLE_PSRAM 0
|
||||||
|
|
||||||
|
// Enables sending messages that are bigger than the predefined message size,
|
||||||
|
// where the message will be sent byte by byte as a fallback instead.
|
||||||
|
// Requires an additional library, see https://github.com/bblanchon/ArduinoStreamUtils for more
|
||||||
|
// information. Simply install that library and the feature will be enabled automatically.
|
||||||
|
#define THINGSBOARD_ENABLE_STREAM_UTILS 0
|
||||||
|
|
||||||
|
// Baud rate for the debugging serial connection
|
||||||
|
// If the Serial output is mangled, ensure to change the monitor speed accordingly to this variable
|
||||||
|
constexpr uint32_t SERIAL_DEBUG_BAUD = 115200U;
|
||||||
|
|
||||||
|
// Enable Serial debug output
|
||||||
|
#define SERIAL_DEBUG true
|
||||||
|
|
||||||
|
// Enable MQTT RPC debug
|
||||||
|
#define MQTT_RPC_DEBUG true
|
||||||
|
|
||||||
|
// Enable Thingsboard library debug
|
||||||
|
#define THINGSBOARD_ENABLE_DEBUG true
|
||||||
|
|
||||||
|
// WIFI parameters
|
||||||
|
constexpr char WIFI_SSID[] = "thingsboard";
|
||||||
|
constexpr char WIFI_PASSWORD[] = "thingsboard";
|
||||||
|
|
||||||
|
// Module actionneur Thingsboard token access
|
||||||
|
constexpr char TOKEN[] = "1voazulw2mqr9avkdonw";
|
||||||
|
|
||||||
|
// Thingsboard server IP address
|
||||||
|
constexpr char THINGSBOARD_SERVER[] = "10.42.0.1";
|
||||||
|
|
||||||
|
// MQTT port used to communicate with the server, 1883 is the default unencrypted MQTT port,
|
||||||
|
// whereas 8883 would be the default encrypted SSL MQTT port
|
||||||
|
#if ENCRYPTED
|
||||||
|
constexpr uint16_t THINGSBOARD_PORT = 8883U;
|
||||||
|
#else
|
||||||
|
constexpr uint16_t THINGSBOARD_PORT = 1883U;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if ENCRYPTED
|
||||||
|
// See https://comodosslstore.com/resources/what-is-a-root-ca-certificate-and-how-do-i-download-it/
|
||||||
|
// on how to get the root certificate of the server we want to communicate with,
|
||||||
|
// this is needed to establish a secure connection and changes depending on the website.
|
||||||
|
constexpr char ROOT_CERT[] = R"(-----BEGIN CERTIFICATE-----
|
||||||
|
MIIFazCCA1OgAwIBAgIRAIIQz7DSQONZRGPgu2OCiwAwDQYJKoZIhvcNAQELBQAw
|
||||||
|
TzELMAkGA1UEBhMCVVMxKTAnBgNVBAoTIEludGVybmV0IFNlY3VyaXR5IFJlc2Vh
|
||||||
|
cmNoIEdyb3VwMRUwEwYDVQQDEwxJU1JHIFJvb3QgWDEwHhcNMTUwNjA0MTEwNDM4
|
||||||
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7bl5AFzgAiIyBpY9umbbjANBgkq
|
||||||
|
hkiG9w0BAQsFAAOCAgEAVR9YqbyyqFDQDLHYGmkgJykIrGF1XIpu+ILlaS/V9lZL
|
||||||
|
ubhzEFnTIZd+50xx+7LSYK05qAvqFyFWhfFQDlnrzuBZ6brJFe+GnY+EgPbk6ZGQ
|
||||||
|
3BebYhtF8GaV0nxvwuo77x/Py9auJ/GpsMiu/X1+mvoiBOv/2X/qkSsisRcOj/KK
|
||||||
|
NFtY2PwByVS5uCbMiogziUwthDyC3+6WVwW6LLv3xLfHTjuCvjHIInNzktHCgKQ5
|
||||||
|
ORAzI4JMPJ+GslWYHb4phowim57iaztXOoJwTdwJx4nLCgdNbOhdjsnvzqvHu7Ur
|
||||||
|
TkXWStAmzOVyyghqpZXjFaH3pO3JLF+l+/+sKAIuvtd7u+Nxe5AW0wdeRlN8NwdC
|
||||||
|
jNPElpzVmbUq4JUagEiuTDkHzsxHpFKVK7q4+63SM1N95R1NbdWhscdCb+ZAJzVc
|
||||||
|
oyi3B43njTOQ5yOf+1CceWxG1bQVs5ZufpsMljq4Ui0/1lvh+wjChP4kqKOJ2qxq
|
||||||
|
4RgqsahDYVvTH9w7jXbyLeiNdd8XM2w9U/t7y0Ff/9yi0GE44Za4rF2LN9d11TPA
|
||||||
|
mRGunUHBcnWEvgJBQl9nJEiU0Zsnvgc/ubhPgXRR4Xq37Z0j4r7g1SgEEzwxA57d
|
||||||
|
emyPxgcYxn/eR44/KJ4EBs+lVDR3veyJm+kXQ99b21/+jh5Xos1AnX5iItreGCc=
|
||||||
|
-----END CERTIFICATE-----
|
||||||
|
)";
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// VMC, LIGHT, HEATER & AC control pins
|
||||||
|
#define VMC_PIN 12
|
||||||
|
#define LIGHT_PIN 13
|
||||||
|
#define HEATER_PIN 27
|
||||||
|
#define AC_PIN 33
|
1
include/version.h
Normal file
1
include/version.h
Normal file
@ -0,0 +1 @@
|
|||||||
|
#define VERSION "0.0.1"
|
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
|
20
platformio.ini
Normal file
20
platformio.ini
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
; 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:adafruit_feather_esp32_v2]
|
||||||
|
platform = espressif32
|
||||||
|
board = adafruit_feather_esp32_v2
|
||||||
|
framework = arduino
|
||||||
|
lib_deps =
|
||||||
|
adafruit/Adafruit NeoPixel@^1.12.5
|
||||||
|
thingsboard/ThingsBoard@^0.15.0
|
||||||
|
|
||||||
|
; Need to be updated
|
||||||
|
upload_port = /dev/cu.usbserial-59100221861
|
87
src/main.cpp
Normal file
87
src/main.cpp
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
#include "config.h"
|
||||||
|
#include "version.h"
|
||||||
|
|
||||||
|
#include <WiFi.h>
|
||||||
|
#include <WiFiClientSecure.h>
|
||||||
|
#include <Adafruit_NeoPixel.h>
|
||||||
|
|
||||||
|
#include <Arduino_MQTT_Client.h>
|
||||||
|
#include <Server_Side_RPC.h>
|
||||||
|
#include <ThingsBoard.h>
|
||||||
|
|
||||||
|
// then these pins will be defined for us
|
||||||
|
#if defined(ADAFRUIT_FEATHER_ESP32_V2) or defined(ARDUINO_ADAFRUIT_ITSYBITSY_ESP32)
|
||||||
|
#define PIN_NEOPIXEL 0
|
||||||
|
#define NEOPIXEL_I2C_POWER 2
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(PIN_NEOPIXEL)
|
||||||
|
Adafruit_NeoPixel pixel(1, PIN_NEOPIXEL, NEO_GRB + NEO_KHZ800);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Initialize underlying client, used to establish a connection
|
||||||
|
#if ENCRYPTED
|
||||||
|
WiFiClientSecure espClient;
|
||||||
|
#else
|
||||||
|
WiFiClient espClient;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Initalize the Mqtt client instance
|
||||||
|
Arduino_MQTT_Client mqttClient(espClient);
|
||||||
|
|
||||||
|
// Maximum size packets will ever be sent or received by the underlying MQTT client,
|
||||||
|
// if the size is to small messages might not be sent or received messages will be discarded
|
||||||
|
constexpr uint16_t MAX_MESSAGE_SEND_SIZE = 128U;
|
||||||
|
constexpr uint16_t MAX_MESSAGE_RECEIVE_SIZE = 128U;
|
||||||
|
constexpr uint8_t MAX_RPC_SUBSCRIPTIONS = 8U;
|
||||||
|
constexpr uint8_t MAX_RPC_RESPONSE = 16U;
|
||||||
|
constexpr uint8_t MAX_RPC_REQUEST = 10U;
|
||||||
|
constexpr uint64_t REQUEST_TIMEOUT_MICROSECONDS = 5000U * 1000U;
|
||||||
|
|
||||||
|
// Maximum amount of attributs we can request or subscribe, has to be set both in the ThingsBoard
|
||||||
|
// template list and Attribute_Request_Callback template list and should be the same as the amount
|
||||||
|
// of variables in the passed array. If it is less not all variables will be requested or subscribed
|
||||||
|
constexpr size_t MAX_ATTRIBUTES = 3U;
|
||||||
|
|
||||||
|
// Initialize used apis
|
||||||
|
Server_Side_RPC<MAX_RPC_SUBSCRIPTIONS, MAX_RPC_RESPONSE> server_rpc;
|
||||||
|
const std::array<IAPI_Implementation*, 1U> apis
|
||||||
|
= { &server_rpc /*, &client_rpc , &shared_update */ };
|
||||||
|
|
||||||
|
// Initialize ThingsBoard instance with the maximum needed buffer size
|
||||||
|
ThingsBoard tb(
|
||||||
|
mqttClient, MAX_MESSAGE_RECEIVE_SIZE, MAX_MESSAGE_SEND_SIZE, Default_Max_Stack_Size, apis);
|
||||||
|
|
||||||
|
// Statuses for subscribing to shared attributes
|
||||||
|
bool subscribed = false;
|
||||||
|
|
||||||
|
// Send once
|
||||||
|
bool once = true;
|
||||||
|
|
||||||
|
void setup()
|
||||||
|
{
|
||||||
|
// Initalize serial connection for debugging
|
||||||
|
#if SERIAL_DEBUG
|
||||||
|
Serial.begin(SERIAL_DEBUG_BAUD);
|
||||||
|
delay(200);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Set VMC, LIGHT, HEATER & AC pin mode as OUTPUT
|
||||||
|
pinMode(VMC_PIN, OUTPUT);
|
||||||
|
pinMode(LIGHT_PIN, OUTPUT);
|
||||||
|
pinMode(HEATER_PIN, OUTPUT);
|
||||||
|
pinMode(AC_PIN, OUTPUT);
|
||||||
|
|
||||||
|
// Set initial value LOW for VMC, LIGHT, HEATER & AC pin
|
||||||
|
digitalWrite(VMC_PIN, LOW);
|
||||||
|
digitalWrite(LIGHT_PIN, LOW);
|
||||||
|
digitalWrite(HEATER_PIN, LOW);
|
||||||
|
digitalWrite(AC_PIN, LOW);
|
||||||
|
|
||||||
|
// Init Wifi connexion
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop()
|
||||||
|
{
|
||||||
|
tb.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…
x
Reference in New Issue
Block a user