Added Melody Struct & Ajusted MQTT Subs and Deserialization
A new Melody Struct was added containing the melody's main attributes. The MQTT Topic Subscriptions were updated to a more proper format. Also added DEV_ID that corresponds to the device's ID or Serial Number. Chnaged the Deserialization function to actually adjust the MelodyStruct's attributes. Added basic play/stop functionality.
This commit is contained in:
42
vesper.ino
42
vesper.ino
@@ -1,31 +1,55 @@
|
||||
#
|
||||
|
||||
#include <WiFi.h>
|
||||
#include <AsyncMqttClient.h>
|
||||
#include <ArduinoJson.h>
|
||||
#include <FS.h>
|
||||
#include <SPIFFS.h>
|
||||
#include <string>
|
||||
|
||||
#define DEV_ID "id-96638646"
|
||||
|
||||
struct melody_attributes {
|
||||
std::string name; // Contains the name of each Melody saved
|
||||
uint16_t id; // The (internal) ID of the selected melody
|
||||
uint32_t duration; // Indicates the total Duration in Minutes
|
||||
bool infinite_play; // Infinite Loop Indicator (If True the melody will loop forever or until stoped, with pauses of "interval duration in between loops")
|
||||
uint16_t interval_duration; // Indicates the Duration of the Interval between finished loops, IF "inf" is true
|
||||
uint8_t speed; // Indicates the Speed in 9 Steps. 1-9 (Steps can be adjusted in the bellEngine function)
|
||||
};
|
||||
|
||||
melody_attributes melody;
|
||||
|
||||
volatile bool playing = false;
|
||||
|
||||
#include "functions.hpp"
|
||||
#include "config.h" // Sustituir con datos de vuestra red
|
||||
#include "JSON_functions.hpp"
|
||||
#include "MQTT.hpp"
|
||||
#include "ESP32_Utils.hpp"
|
||||
#include "ESP32_Utils_MQTT_Async.hpp"
|
||||
#include "melody_handling.hpp"
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
// Initialize Serial Communication (for debuggin)
|
||||
Serial.begin(115200);
|
||||
delay(50);
|
||||
|
||||
delay(500);
|
||||
|
||||
// Initialize SPIFFS
|
||||
if (!SPIFFS.begin(true)) { // 'true' means format SPIFFS if initialization fails
|
||||
Serial.println("Failed to mount SPIFFS");
|
||||
return;
|
||||
}
|
||||
Serial.println("SPIFFS mounted successfully");
|
||||
delay(50);
|
||||
|
||||
// Initialize WiFi and MQTT
|
||||
WiFi.onEvent(WiFiEvent);
|
||||
InitMqtt();
|
||||
|
||||
ConnectWiFi_STA();
|
||||
delay(1000);
|
||||
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
// EXAMPLE PUBLISH. CHANGE THIS, IF NEEDED.
|
||||
//delay(1000);
|
||||
//PublishMqtt(millis());
|
||||
}
|
||||
Reference in New Issue
Block a user