-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
42 changed files
with
1,187 additions
and
263 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
.pio | ||
.vscode | ||
.vscode/* |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
{ | ||
"version": 1, | ||
"author": "", | ||
"editor": "wokwi", | ||
"parts": [ | ||
{ | ||
"type": "board-esp32-devkit-c-v4", | ||
"id": "esp", | ||
"top": -38.4, | ||
"left": -52.76, | ||
"attrs": {} | ||
}, | ||
{ | ||
"type": "wokwi-ky-040", | ||
"id": "encoder1", | ||
"top": 215, | ||
"left": -165.3, | ||
"rotate": 270, | ||
"attrs": {} | ||
}, | ||
{ | ||
"type": "board-ssd1306", | ||
"id": "oled1", | ||
"top": 108.74, | ||
"left": 86.63, | ||
"attrs": { "i2cAddress": "0x3c" } | ||
}, | ||
{ | ||
"type": "wokwi-ntc-temperature-sensor", | ||
"id": "ntc1", | ||
"top": 107.8, | ||
"left": 259.2, | ||
"rotate": 180, | ||
"attrs": {} | ||
}, | ||
{ | ||
"type": "wokwi-buzzer", | ||
"id": "bz1", | ||
"top": -170.4, | ||
"left": 126.6, | ||
"attrs": { "volume": "0.1" } | ||
}, | ||
{ | ||
"type": "wokwi-ntc-temperature-sensor", | ||
"id": "ntc2", | ||
"top": 309.9, | ||
"left": -0.1, | ||
"rotate": 270, | ||
"attrs": {} | ||
} | ||
], | ||
"connections": [ | ||
["esp:TX", "$serialMonitor:RX", "", []], | ||
["esp:RX", "$serialMonitor:TX", "", []], | ||
["encoder1:GND", "esp:GND.1", "black", ["v0"]], | ||
["encoder1:VCC", "esp:5V", "red", ["v0"]], | ||
["encoder1:SW", "esp:27", "#8f4814", ["v0"]], | ||
["encoder1:DT", "esp:26", "green", ["v0"]], | ||
["encoder1:CLK", "esp:25", "orange", ["v0"]], | ||
["oled1:GND", "esp:GND.2", "black", ["v-28.8", "h-38.4", "v-86.4"]], | ||
["oled1:VCC", "esp:5V", "red", ["v-38.4", "h-67.05", "v115.2", "h-115.2"]], | ||
["oled1:SCL", "esp:22", "#8f4814", ["v0"]], | ||
["oled1:SDA", "esp:21", "orange", ["v0"]], | ||
["esp:15", "ntc1:OUT", "green", ["v0", "h28.8", "v-67.2", "h163.2"]], | ||
["esp:3V3", "ntc1:VCC", "red", ["h0.15", "v-48", "h278.4", "v201.6"]], | ||
["ntc1:GND", "esp:GND.3", "black", ["h-48", "v-67.2", "h-153.6", "v-38.4"]], | ||
["bz1:1", "esp:GND.2", "black", ["v0"]], | ||
["bz1:2", "esp:4", "green", ["v105.6", "h-106", "v86.4"]], | ||
["ntc2:OUT", "esp:2", "green", ["v0"]], | ||
["ntc2:VCC", "ntc1:VCC", "red", ["v-67.2", "h163.2", "v-67.2", "h19.2"]], | ||
["ntc2:GND", "ntc1:GND", "black", ["v-38.4", "h153.6", "v-86.4"]] | ||
], | ||
"dependencies": {} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#ifndef _BIOTEMP_HPP_ | ||
#define _BIOTEMP_HPP_ | ||
|
||
#include "global_instances.hpp" | ||
#include "InputController.hpp" | ||
|
||
#endif |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#ifndef _INCLUDE_SECRETS_H_ | ||
#define _INCLUDE_SECRETS_H_ | ||
|
||
#include <pgmspace.h> | ||
|
||
#define WIFI_SSID "Devices" // Network SSID | ||
#define WIFI_PASSWORD NULL // Network password | ||
|
||
#define USERNAME "esp32" // MQTT user to connect to the broker | ||
#define PASSWORD "BioTemp0" // MQTT password to connect to the broker | ||
|
||
#define BROKER_URL "f473eee517ca46888788ad8040276af7.s1.eu.hivemq.cloud" // MQTT broker URL | ||
#define PORT 8883 // MQTT standard port | ||
|
||
// Certificate for secure connection | ||
static const char *root_ca PROGMEM = R"EOF( | ||
-----BEGIN CERTIFICATE----- | ||
MIIFazCCA1OgAwIBAgIRAIIQz7DSQONZRGPgu2OCiwAwDQYJKoZIhvcNAQELBQAw | ||
TzELMAkGA1UEBhMCVVMxKTAnBgNVBAoTIEludGVybmV0IFNlY3VyaXR5IFJlc2Vh | ||
cmNoIEdyb3VwMRUwEwYDVQQDEwxJU1JHIFJvb3QgWDEwHhcNMTUwNjA0MTEwNDM4 | ||
WhcNMzUwNjA0MTEwNDM4WjBPMQswCQYDVQQGEwJVUzEpMCcGA1UEChMgSW50ZXJu | ||
ZXQgU2VjdXJpdHkgUmVzZWFyY2ggR3JvdXAxFTATBgNVBAMTDElTUkcgUm9vdCBY | ||
MTCCAiIwDQYJKoZIhvcNAQEBBQADggIPADCCAgoCggIBAK3oJHP0FDfzm54rVygc | ||
h77ct984kIxuPOZXoHj3dcKi/vVqbvYATyjb3miGbESTtrFj/RQSa78f0uoxmyF+ | ||
0TM8ukj13Xnfs7j/EvEhmkvBioZxaUpmZmyPfjxwv60pIgbz5MDmgK7iS4+3mX6U | ||
A5/TR5d8mUgjU+g4rk8Kb4Mu0UlXjIB0ttov0DiNewNwIRt18jA8+o+u3dpjq+sW | ||
T8KOEUt+zwvo/7V3LvSye0rgTBIlDHCNAymg4VMk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5yOf+1CceWxG1bQVs5ZufpsMljq4Ui0/1lvh+wjChP4kqKOJ2qxq | ||
4RgqsahDYVvTH9w7jXbyLeiNdd8XM2w9U/t7y0Ff/9yi0GE44Za4rF2LN9d11TPA | ||
mRGunUHBcnWEvgJBQl9nJEiU0Zsnvgc/ubhPgXRR4Xq37Z0j4r7g1SgEEzwxA57d | ||
emyPxgcYxn/eR44/KJ4EBs+lVDR3veyJm+kXQ99b21/+jh5Xos1AnX5iItreGCc= | ||
-----END CERTIFICATE----- | ||
)EOF"; | ||
|
||
#endif //_INCLUDE_SECRETS_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#include <biotempMQTTClient.hpp> | ||
|
||
void BioTempMQTTClient::mqttConfig() { | ||
mqtt.config(WIFI_SSID, WIFI_PASSWORD); | ||
} | ||
|
||
void BioTempMQTTClient::publish(const char* topic, String message) { | ||
mqtt.publishMessage(topic, message, false); | ||
} | ||
|
||
String BioTempMQTTClient::getIP() { | ||
return mqtt.getIP(); | ||
} | ||
|
||
String BioTempMQTTClient::getMAC() { | ||
return mqtt.getMAC(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#ifndef _INCLUDE_BIOTEMPMQTTCLIENT_HPP_ | ||
#define _INCLUDE_BIOTEMPMQTTCLIENT_HPP_ | ||
|
||
#include <mqttClient.hpp> | ||
#include <secrets.h> | ||
|
||
/**************************************************************/ | ||
/*! | ||
* @brief BioTemp MQTT interface class. | ||
*/ | ||
/**************************************************************/ | ||
class BioTempMQTTClient { | ||
public: | ||
/**************************************************************/ | ||
/*! | ||
* @brief Publish a message to the specified topic. | ||
* @param topic The topic to publish a message. | ||
* @param message The message to be published. | ||
*/ | ||
/**************************************************************/ | ||
void publish(const char* topic, String message); | ||
|
||
// Configures the MQTT module in the BioTemp context. | ||
void mqttConfig(); | ||
|
||
// Returns the device IP. | ||
String getIP(); | ||
|
||
//Returns the device MAC address. | ||
String getMAC(); | ||
|
||
private: | ||
const char *topic = "test"; // MQTT topic to publish messages | ||
|
||
MQTTClient mqtt = MQTTClient(USERNAME, PASSWORD, root_ca, BROKER_URL, PORT); | ||
}; | ||
|
||
#endif // _INCLUDE_BIOTEMPMQTTCLIENT_HPP_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
#include <mqttClient.hpp> | ||
|
||
void MQTTClient::config(const char* wifi_ssid, const char* wifi_password) { | ||
WiFi.mode(WIFI_STA); | ||
WiFi.begin(wifi_ssid, wifi_password); | ||
|
||
Serial.print("Conectando ao WiFi..."); | ||
|
||
while(WiFi.status() != WL_CONNECTED) { | ||
Serial.print("."); | ||
delay(500); | ||
} | ||
|
||
configMQTT(certificate, broker, port); | ||
} | ||
|
||
void MQTTClient::configMQTT(const char* certificate, const char* broker, const int port) { | ||
espClient.setCACert(certificate); | ||
MQTT.setServer(broker, port); | ||
MQTT.setCallback(callback); | ||
if(!MQTT.connected()) { | ||
connect(username, password); | ||
} | ||
} | ||
|
||
void MQTTClient::mqttLoop() { | ||
MQTT.loop(); | ||
} | ||
|
||
String MQTTClient::getIP() { | ||
ip = WiFi.localIP().toString(); | ||
return ip; | ||
} | ||
|
||
String MQTTClient::getMAC() { | ||
mac_address = WiFi.macAddress(); | ||
return mac_address; | ||
} | ||
|
||
void callback(char *topic, byte *payload, unsigned int length) { | ||
Serial.print("Message arrived in topic: "); | ||
Serial.println(topic); | ||
Serial.print("Message:"); | ||
for (int i = 0; i < length; i++) { | ||
Serial.print((char) payload[i]); | ||
} | ||
Serial.println(); | ||
Serial.println("-----------------------"); | ||
} | ||
|
||
void MQTTClient::publishMessage(const char* topic, String payload , boolean retained){ | ||
if (MQTT.publish(topic, payload.c_str(), true)) | ||
Serial.println("Message published ["+String(topic)+"]: "+payload); | ||
} | ||
|
||
void MQTTClient::connect(const char* user, const char* password) { | ||
while(!MQTT.connected()) { | ||
String client_id = "esp32-client-"; | ||
client_id += String(WiFi.macAddress()); | ||
Serial.printf("The client %s connects to MQTT broker\n", client_id.c_str()); | ||
if (MQTT.connect(client_id.c_str(), user, password)) { | ||
Serial.println("Broker connected"); | ||
//MQTT.subscribe(topic); //Verificar necessidade | ||
} else { | ||
Serial.print("failed with state "); | ||
Serial.print(MQTT.state()); | ||
delay(2000); | ||
} | ||
} | ||
} | ||
|
||
MQTTClient::MQTTClient(const char* mqttUser, | ||
const char* mqttPass, | ||
const char* mqttCertificate, | ||
const char* mqttBroker, | ||
const int mqttPort) { | ||
|
||
username = mqttUser; | ||
password = mqttPass; | ||
certificate = mqttCertificate; | ||
broker = mqttBroker; | ||
port = mqttPort; | ||
} |
Oops, something went wrong.