mqtt_open
This commit is contained in:
@@ -48,38 +48,6 @@ unsigned long millis()
|
|||||||
#define OP_ANALOG_WRITE 3
|
#define OP_ANALOG_WRITE 3
|
||||||
#define OP_PIN_MODE 4
|
#define OP_PIN_MODE 4
|
||||||
|
|
||||||
typedef struct PinIO
|
|
||||||
{
|
|
||||||
unsigned char mode;
|
|
||||||
int ivalue;
|
|
||||||
double dvalue;
|
|
||||||
int error; // % = 1 /error ex 1 / 20 = 5 %
|
|
||||||
double efficacite; // 0 - 100%
|
|
||||||
unsigned long start;
|
|
||||||
unsigned long time;
|
|
||||||
double duration;
|
|
||||||
unsigned int nb; // compteur d'activation
|
|
||||||
int memory;
|
|
||||||
unsigned char raising;
|
|
||||||
unsigned char falling;
|
|
||||||
} PinIO;
|
|
||||||
|
|
||||||
PinIO _digital[256];
|
|
||||||
|
|
||||||
void pinMode(unsigned char p, unsigned char mode)
|
|
||||||
{
|
|
||||||
_digital[p].mode = 0x01 | mode;
|
|
||||||
|
|
||||||
_digital[p].ivalue = 0;
|
|
||||||
_digital[p].dvalue = 0.0;
|
|
||||||
|
|
||||||
_digital[p].nb = 0;
|
|
||||||
_digital[p].time = 0.0;
|
|
||||||
_digital[p].duration = 0.0;
|
|
||||||
_digital[p].start = 0;
|
|
||||||
_digital[p].raising = 0;
|
|
||||||
_digital[p].memory = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int b0, b1, b2, b3, b4, b5, b6, b7;
|
int b0, b1, b2, b3, b4, b5, b6, b7;
|
||||||
int s0, s1, s2, s3, s4, s5, s6, s7;
|
int s0, s1, s2, s3, s4, s5, s6, s7;
|
||||||
@@ -150,7 +118,20 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void mqtt_open(mqtt::async_client* client) {
|
||||||
|
mqtt::connect_options connOpts;
|
||||||
|
connOpts.set_clean_session(true);
|
||||||
|
connOpts.set_user_name("admin");
|
||||||
|
connOpts.set_password("geii2025");
|
||||||
|
try {
|
||||||
|
client->connect(connOpts)->wait();
|
||||||
|
client->start_consuming();
|
||||||
|
client->subscribe(TOPIC, QOS)->wait();
|
||||||
|
} catch (const mqtt::exception &exc) {
|
||||||
|
std::cerr << "Erreur MQTT: " << exc.what() << "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void mqtt_close() {
|
void mqtt_close() {
|
||||||
try {
|
try {
|
||||||
@@ -163,27 +144,6 @@ void mqtt_close() {
|
|||||||
}
|
}
|
||||||
// ************************************************************
|
// ************************************************************
|
||||||
|
|
||||||
/* KEYBOARD */
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
int input;
|
|
||||||
int vKey;
|
|
||||||
} KeyboardIO;
|
|
||||||
|
|
||||||
#define NB_KEYBOARD 10
|
|
||||||
KeyboardIO _keyboard[NB_KEYBOARD];
|
|
||||||
|
|
||||||
void LireClavier(int ch)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < NB_KEYBOARD; i++)
|
|
||||||
{
|
|
||||||
_digital[_keyboard[i].input].ivalue = (ch == _keyboard[i].vKey);
|
|
||||||
_digital[_keyboard[i].input].raising = _digital[_keyboard[i].input].ivalue > _digital[_keyboard[i].input].memory;
|
|
||||||
_digital[_keyboard[i].input].falling = _digital[_keyboard[i].input].ivalue < _digital[_keyboard[i].input].memory;
|
|
||||||
_digital[_keyboard[i].input].memory = _digital[_keyboard[i].input].ivalue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ********************************************************
|
/* ********************************************************
|
||||||
* TEMPORISATION RETARD A LA MONTEE *
|
* TEMPORISATION RETARD A LA MONTEE *
|
||||||
@@ -411,87 +371,3 @@ class MiseAEchelle
|
|||||||
float maxEntree;
|
float maxEntree;
|
||||||
float maxSortie;
|
float maxSortie;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* READ */
|
|
||||||
|
|
||||||
int digitalRead(int p)
|
|
||||||
{
|
|
||||||
return ((_digital[p].mode & IO_INPUT) && (_digital[p].mode & DIGITAL) && (_digital[p].mode & 0x01)) ? _digital[p].ivalue : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
double analogRead(int p)
|
|
||||||
{
|
|
||||||
return ((_digital[p].mode & IO_INPUT) && (_digital[p].mode & ANALOG) && (_digital[p].mode & 0x01)) ? _digital[p].dvalue : 0.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* WRITE */
|
|
||||||
|
|
||||||
void digitalWrite(unsigned int p, int value)
|
|
||||||
{
|
|
||||||
if (p > 255)
|
|
||||||
{
|
|
||||||
printf("Pin %d is out of Range.", p);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// En panne !
|
|
||||||
if (!(_digital[p].mode & 0x01))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(_digital[p].mode & IO_OUTPUT && _digital[p].mode & DIGITAL))
|
|
||||||
{
|
|
||||||
printf("Pin %d is not a digital input.", p);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned long m = millis();
|
|
||||||
|
|
||||||
if (value != _digital[p].ivalue)
|
|
||||||
{
|
|
||||||
_digital[p].time = _digital[p].time > 5000 ? 0 : 5000 - _digital[p].time;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_digital[p].time += m - _digital[p].start;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (value && !_digital[p].ivalue)
|
|
||||||
{
|
|
||||||
_digital[p].start = m;
|
|
||||||
_digital[p].nb += 1;
|
|
||||||
}
|
|
||||||
else if (value)
|
|
||||||
{
|
|
||||||
_digital[p].duration += dt;
|
|
||||||
}
|
|
||||||
|
|
||||||
_digital[p].raising = (_digital[p].memory < _digital[p].ivalue);
|
|
||||||
_digital[p].falling = (_digital[p].memory > _digital[p].ivalue);
|
|
||||||
_digital[p].memory = _digital[p].ivalue;
|
|
||||||
_digital[p].ivalue = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
void analogWrite(unsigned int p, double value)
|
|
||||||
{
|
|
||||||
if (p > 31)
|
|
||||||
{
|
|
||||||
printf("Pin %d is out of Range.", p);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// En panne
|
|
||||||
if (!(_digital[p].mode & 0x01))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(_digital[p].mode & IO_OUTPUT) || !(_digital[p].mode & ANALOG))
|
|
||||||
{
|
|
||||||
printf("Pin %d is not a analog input.", p);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
_digital[p].dvalue = value;
|
|
||||||
}
|
|
||||||
|
|||||||
13
main.cpp
13
main.cpp
@@ -5,22 +5,13 @@
|
|||||||
#include "mqtt/async_client.h"
|
#include "mqtt/async_client.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
callback cb;
|
callback cb;
|
||||||
client.set_callback(cb);
|
client.set_callback(cb);
|
||||||
|
|
||||||
mqtt::connect_options connOpts;
|
mqtt_open(&client);
|
||||||
connOpts.set_clean_session(true);
|
|
||||||
connOpts.set_user_name("admin");
|
|
||||||
connOpts.set_password("geii2025");
|
|
||||||
try {
|
|
||||||
client.connect(connOpts)->wait();
|
|
||||||
client.start_consuming();
|
|
||||||
client.subscribe(TOPIC, QOS)->wait();
|
|
||||||
} catch (const mqtt::exception &exc) {
|
|
||||||
std::cerr << "Erreur MQTT: " << exc.what() << "\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user