Avro
PILOTE PRO
- Messages
- 1 918
- Réactions
- 255
Bonjour,
j'ai branché un écran à encre électronique et sa carte Arduino ESP32 -Wrover Le problème est que mes variables restent désespérément à 0
int VariablesIn[] = {204,205,206}; // les variables SIOC écoutées
parkingBrakes = Variable[VariablesIn[0]];
yawDamper = Variable[VariablesIn[1]];
pitot = Variable[VariablesIn[2]];
Sioc monitor me donne les bonnes valeurs, c'est le script Arduino qui ne fait rien avec. Une idée ?
j'ai branché un écran à encre électronique et sa carte Arduino ESP32 -Wrover Le problème est que mes variables restent désespérément à 0
int VariablesIn[] = {204,205,206}; // les variables SIOC écoutées
parkingBrakes = Variable[VariablesIn[0]];
yawDamper = Variable[VariablesIn[1]];
pitot = Variable[VariablesIn[2]];
Sioc monitor me donne les bonnes valeurs, c'est le script Arduino qui ne fait rien avec. Une idée ?
C-like:
#ifndef BOARD_HAS_PSRAM
#error "Please enable PSRAM !!!"
#endif
#include <Arduino.h>
#include <SPI.h>
#include <Wire.h>
#include "epd_driver.h"
#include "open24b.h"
#include "firasans.h"
#include <WiFiUdp.h>
#include <ArduinoOTA.h>
//Ecran *************************************************************************/
#define BATT_PIN 36
#define SD_MISO 12
#define SD_MOSI 13
#define SD_SCLK 14
#define SD_CS 15
//Variables **********************************************************************/
uint8_t *framebuffer;
// .width = 960,
// .height = 540,
Rect_t area = {
.x = 100,
.y = 160,
.width = 300,
.height = 60,
};
int cursor_x = 100;
int cursor_y = 100;
char wifinet[25] = "WiFi: ";
// -------------------- VERSION 1.1.0 --------------------------------------------/
//Wifi **************************************************************************/
const char* host = "esp32AlertMessages";
const char* ssid = "mabox";
const char* password = "monmotdepasse";
// config static IP
IPAddress ip(192, 168, 1, 501); // Remplacer les XXX pour faire correspondre à l'adresse IP que vous voulez donner au système
IPAddress gateway(192, 168, 1, 1); // Remplacer les XXX pour faire correspondre à l'adresse IP de la passerelle de votre reseau (generalement l'adresse IP de votre Box internet).
IPAddress subnet(255, 255, 255, 0); // le sous reseau (generalement pas besoin d'y toucher
IPAddress serveriocp(192, 168, 1, 20); // Remplacer les XXX pour faire correspondre à l'adresse IP du PC sur lequel est exécuté SIOC
IPAddress myDns1(1, 1, 1, 1);
IPAddress myDns2(8, 8, 8, 8);
//WebServer server(80);
WiFiClient client;
//int status = WL_IDLE_STATUS;
//byte mac[6];
//IOCP **************************************************************************/
char line[64];
String stringVariable;
String stringNumVariable;
//bool debug = false;
float Variable[1500];
bool ConnectionIOCP = false;
int VariablesIn[] = {204,205,206}; // les variables SIOC écoutées
const int NbVariablesIn = (sizeof(VariablesIn) / sizeof(VariablesIn[0]));
// variables
int parkingBrakes = 0;
int yawDamper = 0;
int pitot = 0;
//SETUP **************************************************************************/
void setup()
{
Serial.begin(115200);
SPI.begin(SD_SCLK, SD_MISO, SD_MOSI);
epd_init();
framebuffer = (uint8_t *)ps_calloc(sizeof(uint8_t), EPD_WIDTH * EPD_HEIGHT / 2);
if (!framebuffer) {
writeln((GFXfont *)&FiraSans, "alloc memory failed !!!", &cursor_x, &cursor_y, NULL);
while (1);
}
memset(framebuffer, 0xFF, EPD_WIDTH * EPD_HEIGHT / 2);
epd_poweron();
epd_clear();
WiFi.mode(WIFI_STA);
if (!WiFi.config(ip, gateway, subnet, myDns1, myDns2)) {
writeln((GFXfont *)&FiraSans, "STA Failed to configure", &cursor_x, &cursor_y, NULL);
}
// Connect to WiFi network
WiFi.begin(ssid, password);
while (WiFi.waitForConnectResult() != WL_CONNECTED) {
writeln((GFXfont *)&FiraSans, "Connection Failed! Rebooting...", &cursor_x, &cursor_y, NULL);
delay(5000);
ESP.restart();
}
strcat(wifinet, ssid); // concaténation de chaine
writeln((GFXfont *)&FiraSans, wifinet, &cursor_x, &cursor_y, NULL);
ArduinoOTA.onStart([]() {
String type;
if (ArduinoOTA.getCommand() == U_FLASH) {
type = "sketch";
} else { // U_SPIFFS
type = "filesystem";
}
// NOTE: if updating SPIFFS this would be the place to unmount SPIFFS using SPIFFS.end()
cursor_x = 100;
cursor_y = 200;
writeln((GFXfont *)&FiraSans, "Start updating ", &cursor_x, &cursor_y, NULL);
});
ArduinoOTA.onEnd([]() {
//Serial.println("\nEnd");
});
ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
});
ArduinoOTA.onError([](ota_error_t error) {
Serial.printf("Error[%u]: ", error);
cursor_x = 100;
cursor_y = 200;
if (error == OTA_AUTH_ERROR) {
writeln((GFXfont *)&FiraSans, "Auth Failed", &cursor_x, &cursor_y, NULL);
} else if (error == OTA_BEGIN_ERROR) {
writeln((GFXfont *)&FiraSans, "Begin Failed", &cursor_x, &cursor_y, NULL);
} else if (error == OTA_CONNECT_ERROR) {
writeln((GFXfont *)&FiraSans, "Connect Failed", &cursor_x, &cursor_y, NULL);
} else if (error == OTA_RECEIVE_ERROR) {
writeln((GFXfont *)&FiraSans, "Receive Failed", &cursor_x, &cursor_y, NULL);
} else if (error == OTA_END_ERROR) {
writeln((GFXfont *)&FiraSans, "End Failed", &cursor_x, &cursor_y, NULL);
}
});
ArduinoOTA.begin();
cursor_x = 100;
cursor_y = 200;
writeln((GFXfont *)&FiraSans, "Waiting IOCP", &cursor_x, &cursor_y, NULL);
ArduinoOTA.handle();
while (!ConnectionIOCP) {
cursor_x = 100;
cursor_y = 200;
ArduinoOTA.handle();
// if you get a connection, report back via serial:
if (client.connect(serveriocp, 8092)) {
ConnectionIOCP = true;
epd_clear_area_cycles(area, 3, 100);
writeln((GFXfont *)&FiraSans, "IOCP connected", &cursor_x, &cursor_y, NULL);
} else {
ConnectionIOCP = false;
// if you didn't get a connection to the server:
cursor_x = 100;
cursor_y = 300;
writeln((GFXfont *)&FiraSans, "connection to IOCP server failed", &cursor_x, &cursor_y, NULL);
}
}
//epd_fill_rect(0, 0, 200, 200, 255, framebuffer);
//epd_write_line(0, 0, 500, 500, 0, framebuffer);
//epd_push_pixels(area, 10, 255);
//epd_clear_area_cycles(area, 20, 10);
//epd_draw_circle(300, 300, 200, 0, framebuffer);
//epd_poweroff();
}
void loop()
{
ArduinoOTA.handle();
TaskRead();
// lecture des variables
parkingBrakes = Variable[VariablesIn[0]];
yawDamper = Variable[VariablesIn[1]];
pitot = Variable[VariablesIn[2]];
char pb1[12];
sprintf(pb1, "PB %d ", parkingBrakes);
char pb2[12];
sprintf(pb2, "YD %d ", yawDamper);
char pb3[12];
sprintf(pb3, "PT %d ", pitot);
//epd_poweron();
epd_clear();
cursor_x = 0;
cursor_y = 40;
writeln((GFXfont *)&OpenSans24B, pb1, &cursor_x, &cursor_y, NULL);
writeln((GFXfont *)&OpenSans24B, pb2, &cursor_x, &cursor_y, NULL);
writeln((GFXfont *)&OpenSans24B, pb3, &cursor_x, &cursor_y, NULL);
cursor_x = 0;
cursor_y = 101;
if (parkingBrakes == 0) {
writeln((GFXfont *)&OpenSans24B, "PARKING BRAKES ON", &cursor_x, &cursor_y, NULL);
}
cursor_x = 0;
cursor_y = 162;
if (yawDamper == 0) {
writeln((GFXfont *)&OpenSans24B, "YAW DAMPER OFF", &cursor_x, &cursor_y, NULL);
}
cursor_x = 0;
cursor_y = 223;
if (pitot == 0) {
writeln((GFXfont *)&OpenSans24B, "PITOT/STALL HEAT OFF", &cursor_x, &cursor_y, NULL);
}
/*cursor_x = 0;
cursor_y = 284;
writeln((GFXfont *)&OpenSans24B, string4, &cursor_x, &cursor_y, NULL);
cursor_x = 0;
cursor_y = 345;
writeln((GFXfont *)&OpenSans24B, string4, &cursor_x, &cursor_y, NULL);
cursor_x = 0;
cursor_y = 406;
writeln((GFXfont *)&OpenSans24B, string4, &cursor_x, &cursor_y, NULL);
cursor_x = 0;
cursor_y = 467;
writeln((GFXfont *)&OpenSans24B, string4, &cursor_x, &cursor_y, NULL);
cursor_x = 0;
cursor_y = 528;
writeln((GFXfont *)&OpenSans24B, string4, &cursor_x, &cursor_y, NULL);*/
//epd_poweroff_all();
}
//Fonctions *********************************************************************/
void TaskRead() // This is a task.
{
int NumVariable;
double VarTemp;
cursor_x = 100;
cursor_y = 200;
// if there are incoming bytes available
// from the server, read them and print them:
if (client)
{
String header = "";
while (client.connected())
{
ArduinoOTA.handle();
if (client.available())
{
char c = client.read();
header += c;
if (c == '\n')
{
if (header.indexOf("Resp:") >= 0)
{
cursor_x = 200;
cursor_y = 400;
writeln((GFXfont *)&OpenSans24B, "Yes", &cursor_x, &cursor_y, NULL);
int NextEgalPos = 0;
int Next2PointPos = 0;
NextEgalPos = header.indexOf("=", NextEgalPos);
Next2PointPos = header.indexOf(":", Next2PointPos);
while ((Next2PointPos > 0) and (NextEgalPos > 0 ))
{
stringNumVariable = header.substring(Next2PointPos + 1, NextEgalPos);
NumVariable = stringNumVariable.toInt();
Next2PointPos = header.indexOf(":", Next2PointPos + 1);
if (Next2PointPos <= 0) stringVariable = header.substring(NextEgalPos + 1, header.length());
else stringVariable = header.substring(NextEgalPos + 1, Next2PointPos);
VarTemp = stringVariable.toInt();
Variable[NumVariable] = VarTemp;
NextEgalPos = header.indexOf("=", NextEgalPos + 1);
}
break;
}
else if (header.indexOf("Vivo:") >= 0)
{
cursor_x = 0;
cursor_y = 400;
writeln((GFXfont *)&OpenSans24B, "Echec", &cursor_x, &cursor_y, NULL);
break;
}
}
}
}
header = "";
}
else
{
ConnectionIOCP = false;
while (!ConnectionIOCP) {
cursor_x = 100;
cursor_y = 300;
ArduinoOTA.handle();
// if you get a connection, report back via serial:
if (client.connect(serveriocp, 8092)) {
ConnectionIOCP = true;
char monip[20];
sprintf(monip, "IP %c ", client.remoteIP());
writeln((GFXfont *)&OpenSans24B, "connected to ", &cursor_x, &cursor_y, NULL);
writeln((GFXfont *)&OpenSans24B, monip, &cursor_x, &cursor_y, NULL);
for (int i = 0; i < NbVariablesIn; i++) {
sprintf(line, "%d:", VariablesIn[i]);
writeln((GFXfont *)&OpenSans24B, line, &cursor_x, &cursor_y, NULL);
}
client.println("");
} else {
ConnectionIOCP = false;
// if you didn't get a connection to the server:
writeln((GFXfont *)&OpenSans24B, "connection to IOCP server failed", &cursor_x, &cursor_y, NULL);
}
}
}
}