Plattformio Arduino IDE Compilerproblem

Der chaotische Hauptfaden

Moderatoren: Heaterman, Finger, Sven, TDI, Marsupilami72, duese

Antworten
Benutzeravatar
Hightech
Beiträge: 11306
Registriert: So 11. Aug 2013, 18:37

Plattformio Arduino IDE Compilerproblem

Beitrag von Hightech »

Moin,
ich hab hier einen Arduino-Code für die ESP32-Cam, der compiliert in der Arduino IDE korrekt und das Programm läuft normal.
Wenn ich den aber mit dem PlattformIO compiliere bekomme ich zwar keine Fehlermeldung, aber das Programm macht einen ssl Fehler.
Was kann das sein?
Der Fehler ist:

Code: Alles auswählen

Connect to api.telegram.org
[E][WiFiClientSecure.cpp:133] connect(): start_ssl_client: -1
Connected to api.telegram.org failed.

Der Compiler wirf nur diese Warunung:

Code: Alles auswählen

/home/boris/.platformio/packages/framework-arduinoespressif32/cores/esp32/esp32-hal-spi.c: In function 'spiTransferBytesNL':
/home/boris/.platformio/packages/framework-arduinoespressif32/cores/esp32/esp32-hal-spi.c:922:39: warning: initialization from incompatible pointer type [-Wincompatible-pointer-types]
                 uint8_t * last_out8 = &result[c_longs-1];
                                       ^
/home/boris/.platformio/packages/framework-arduinoespressif32/cores/esp32/esp32-hal-spi.c:923:40: warning: initialization from incompatible pointer type [-Wincompatible-pointer-types]
                 uint8_t * last_data8 = &last_data;
Der komplette Code:

Code: Alles auswählen


/*
  Rui Santos
  Complete project details at https://RandomNerdTutorials.com/telegram-esp32-cam-photo-arduino/

  Permission is hereby granted, free of charge, to any person obtaining a copy
  of this software and associated documentation files.

  The above copyright notice and this permission notice shall be included in all
  copies or substantial portions of the Software.

  Adapted by Pollux Labs – https://polluxlabs.net
*/

#include <Arduino.h>
#include <dummy.h>
#include <WiFi.h>
#include <WiFiClientSecure.h>
#include "soc/soc.h"
#include "soc/rtc_cntl_reg.h"
#include "esp_camera.h"
#include <UniversalTelegramBot.h>

const char* ssid = "iPhone";
const char* password = "qwertzuiop";

// Initialize Telegram BOT
String BOTtoken = "1927455610:AAHjkkD5PaImM7PZLCoOc";  // your Bot Token (Get from Botfather)

// Use @myidbot to find out the chat ID of an individual or a group
// Also note that you need to click "start" on a bot before it can
// message you
String CHAT_ID = "-514352976";

bool sendPhoto = false;

WiFiClientSecure clientTCP;
UniversalTelegramBot bot(BOTtoken, clientTCP);

//Pin of the motion sensor
#define PIR_PIN 12

// flash lamp IO
#define LAMP 4


//CAMERA_MODEL_AI_THINKER
#define PWDN_GPIO_NUM     32
#define RESET_GPIO_NUM    -1
#define XCLK_GPIO_NUM      0
#define SIOD_GPIO_NUM     26
#define SIOC_GPIO_NUM     27

#define Y9_GPIO_NUM       35
#define Y8_GPIO_NUM       34
#define Y7_GPIO_NUM       39
#define Y6_GPIO_NUM       36
#define Y5_GPIO_NUM       21
#define Y4_GPIO_NUM       19
#define Y3_GPIO_NUM       18
#define Y2_GPIO_NUM        5
#define VSYNC_GPIO_NUM    25
#define HREF_GPIO_NUM     23
#define PCLK_GPIO_NUM     22

  //Stores the camera configuration parameters
  camera_config_t config;

void configInitCamera() {
  camera_config_t config;
  config.ledc_channel = LEDC_CHANNEL_0;
  config.ledc_timer = LEDC_TIMER_0;
  config.pin_d0 = Y2_GPIO_NUM;
  config.pin_d1 = Y3_GPIO_NUM;
  config.pin_d2 = Y4_GPIO_NUM;
  config.pin_d3 = Y5_GPIO_NUM;
  config.pin_d4 = Y6_GPIO_NUM;
  config.pin_d5 = Y7_GPIO_NUM;
  config.pin_d6 = Y8_GPIO_NUM;
  config.pin_d7 = Y9_GPIO_NUM;
  config.pin_xclk = XCLK_GPIO_NUM;
  config.pin_pclk = PCLK_GPIO_NUM;
  config.pin_vsync = VSYNC_GPIO_NUM;
  config.pin_href = HREF_GPIO_NUM;
  config.pin_sscb_sda = SIOD_GPIO_NUM;
  config.pin_sscb_scl = SIOC_GPIO_NUM;
  config.pin_pwdn = PWDN_GPIO_NUM;
  config.pin_reset = RESET_GPIO_NUM;
  config.xclk_freq_hz = 20000000;
  config.pixel_format = PIXFORMAT_JPEG;

  //init with high specs to pre-allocate larger buffers
  if (psramFound()) {
    config.frame_size = FRAMESIZE_UXGA;
    config.jpeg_quality = 10;  //0-63 lower number means higher quality
    config.fb_count = 2;
  } else {
    config.frame_size = FRAMESIZE_SVGA;
    config.jpeg_quality = 12;  //0-63 lower number means higher quality
    config.fb_count = 1;
  }
  // camera init
  esp_err_t err = esp_camera_init(&config);
  if (err != ESP_OK) {
    Serial.printf("Camera init failed with error 0x%x", err);
    delay(1000);
    ESP.restart();
  }

  // Drop down frame size for higher initial frame rate
  sensor_t * s = esp_camera_sensor_get();
  s->set_framesize(s, FRAMESIZE_XGA);  // CIF|UXGA|SXGA|XGA|SVGA|VGA|CIF|QVGA|HQVGA|QQVGA

 //sensor_t * s = esp_camera_sensor_get();
  s->set_brightness(s, 0);     // -2 to 2
  s->set_contrast(s, 0);       // -2 to 2
  s->set_saturation(s, 0);     // -2 to 2
  s->set_special_effect(s, 0); // 0 to 6 (0 - No Effect, 1 - Negative, 2 - Grayscale, 3 - Red Tint, 4 - Green Tint, 5 - Blue Tint, 6 - Sepia)
  s->set_whitebal(s, 1);       // 0 = disable , 1 = enable
  s->set_awb_gain(s, 1);       // 0 = disable , 1 = enable
  s->set_wb_mode(s, 3);        // 0 to 4 - if awb_gain enabled (0 - Auto, 1 - Sunny, 2 - Cloudy, 3 - Office, 4 - Home)
  s->set_exposure_ctrl(s, 0);  // 0 = disable , 1 = enable
  s->set_aec2(s, 0);           // 0 = disable , 1 = enable
  s->set_ae_level(s, 0);       // -2 to 2
  s->set_aec_value(s, 500);    // 0 to 1200
  s->set_gain_ctrl(s, 1);      // 0 = disable , 1 = enable
  s->set_agc_gain(s, 0);       // 0 to 30
  s->set_gainceiling(s, (gainceiling_t)0);  // 0 to 6
  s->set_bpc(s, 0);            // 0 = disable , 1 = enable
  s->set_wpc(s, 1);            // 0 = disable , 1 = enable
  s->set_raw_gma(s, 1);        // 0 = disable , 1 = enable
  s->set_lenc(s, 1);           // 0 = disable , 1 = enable
  s->set_hmirror(s, 0);        // 0 = disable , 1 = enable
  s->set_vflip(s, 1);          // 0 = disable , 1 = enable
  s->set_dcw(s, 1);            // 0 = disable , 1 = enable
  s->set_colorbar(s, 0);       // 0 = disable , 1 = enable

}

String sendPhotoTelegram() {
  const char* myDomain = "api.telegram.org";
  String getAll = "";
  String getBody = "";
  digitalWrite(LAMP, HIGH);
  delay(1000);
  camera_fb_t * fb = NULL;
  fb = esp_camera_fb_get();
  digitalWrite(LAMP, LOW);
  if (!fb) {
    Serial.println("Camera capture failed");
    delay(1000);
    ESP.restart();
    return "Camera capture failed";
  }
  Serial.println("Connect to " + String(myDomain));


  if (clientTCP.connect(myDomain, 443)) {
    Serial.println("Connection successful");

    String head = "--RandomNerdTutorials\r\nContent-Disposition: form-data; name=\"chat_id\"; \r\n\r\n" + CHAT_ID + "\r\n--RandomNerdTutorials\r\nContent-Disposition: form-data; name=\"photo\"; filename=\"esp32-cam.jpg\"\r\nContent-Type: image/jpeg\r\n\r\n";
    String tail = "\r\n--RandomNerdTutorials--\r\n";

    uint16_t imageLen = fb->len;
    uint16_t extraLen = head.length() + tail.length();
    uint16_t totalLen = imageLen + extraLen;

    clientTCP.println("POST /bot" + BOTtoken + "/sendPhoto HTTP/1.1");
    clientTCP.println("Host: " + String(myDomain));
    clientTCP.println("Content-Length: " + String(totalLen));
    clientTCP.println("Content-Type: multipart/form-data; boundary=RandomNerdTutorials");
    clientTCP.println();
    clientTCP.print(head);

    uint8_t *fbBuf = fb->buf;
    size_t fbLen = fb->len;
    for (size_t n = 0; n < fbLen; n = n + 1024) {
      if (n + 1024 < fbLen) {
        clientTCP.write(fbBuf, 1024);
        fbBuf += 1024;
      }
      else if (fbLen % 1024 > 0) {
        size_t remainder = fbLen % 1024;
        clientTCP.write(fbBuf, remainder);
      }
    }

    clientTCP.print(tail);

    esp_camera_fb_return(fb);

    int waitTime = 10000;   // timeout 10 seconds
    long startTimer = millis();
    boolean state = false;

    while ((startTimer + waitTime) > millis())
    {
      Serial.print(".");
      delay(100);
      while (clientTCP.available())
      {
        char c = clientTCP.read();
        if (c == '\n')
        {
          if (getAll.length() == 0) state = true;
          getAll = "";
        }
        else if (c != '\r')
          getAll += String(c);
        if (state == true) getBody += String(c);
        startTimer = millis();
      }
      if (getBody.length() > 0) break;
    }
    clientTCP.stop();
    Serial.println(getBody);
  }
  else {
    getBody = "Connected to api.telegram.org failed.";
    Serial.println("Connected to api.telegram.org failed.");
  }
  return getBody;
}

void setup() {

  pinMode(LAMP, OUTPUT);

  WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 0);
  // Init Serial Monitor
  Serial.begin(115200);

  //Set PIR
  pinMode(PIR_PIN, INPUT);

  // Config and init the camera
  configInitCamera();

  // Connect to Wi-Fi
  WiFi.mode(WIFI_STA);
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
    delay(500);
  }
  Serial.println();
  Serial.print("ESP32-CAM IP Address: ");
  Serial.println(WiFi.localIP());
}

void loop() {

  if (digitalRead(PIR_PIN)) {
    pinMode(PIR_PIN, OUTPUT);
    digitalWrite(PIR_PIN, HIGH);


    Serial.println("wait");
    //delay(1000);
    Serial.println("Preparing photo");
    sendPhotoTelegram();
    Serial.println("photo sent");
    digitalWrite(PIR_PIN, LOW);
    Serial.println("PIR PIN LOW");

    pinMode(PIR_PIN, INPUT);
    Serial.println("PIR INPUT");
    Serial.println("wait");
    delay(1000);
  }
}
Zuletzt geändert von Hightech am Do 5. Aug 2021, 17:35, insgesamt 1-mal geändert.
ch_ris
Beiträge: 3029
Registriert: Mo 30. Nov 2015, 10:08

Re: Plattformio Arduino IDE Compilerproblem

Beitrag von ch_ris »

beides der gleiche gcc? sind die compiler flags gleich?

code problem? weis ich nicht, vielleicht hier was:
https://stackoverflow.com/search?q=init ... 721ffb9218
sirell
Beiträge: 606
Registriert: Mi 8. Apr 2015, 13:38
Wohnort: DE/Herzogenaurach

Re: Plattformio Arduino IDE Compilerproblem

Beitrag von sirell »

Schau mal welchen Arduinocore PlattformIO verwendet.
Da gab es ein paar Bugs. Aktualisieren könnte schon reichen.
Ich glaube 1.0.4 oder 1.0.5 hat das behoben.
virtexultra
Beiträge: 127
Registriert: So 9. Dez 2018, 11:30

Re: Plattformio Arduino IDE Compilerproblem

Beitrag von virtexultra »

Kann es sein das die Arduino Umgebung mehr in den Flash lädt als PlatformIO? Ich denke da insbesonders an die TLS Certs.
Du könntest vorher mal clientTCP.setInsecure() ausführen. Dann sollte ein fehlendes/falsches Zertifikat kein Problem mehr darstellen.
Alternativ würde ich DNS ausschließen und api.telegram.org mal als IP eintragen.

Zur Diagnose mal in der platformio.ini build_flags = -DCORE_DEBUG_LEVEL=5 setzen um die ganzen Debug Ausgaben der mbtls zu erhalten.
sirell
Beiträge: 606
Registriert: Mi 8. Apr 2015, 13:38
Wohnort: DE/Herzogenaurach

Re: Plattformio Arduino IDE Compilerproblem

Beitrag von sirell »

api.telegram.org geht nur über https. Da geht kein Downgrade mehr.

Soweit ich weiß bindet PlatformIO auch nur den ESP Arduino Core ein.
Sollte sich also (bei gleichen Versionen) auf beiden IDEs gleich verhalten.
Benutzeravatar
Hightech
Beiträge: 11306
Registriert: So 11. Aug 2013, 18:37

Re: Plattformio Arduino IDE Compilerproblem

Beitrag von Hightech »

Der Output mit Debug=5 ist:

Code: Alles auswählen

Connect to api.telegram.org
[V][ssl_client.cpp:59] start_ssl_client(): Free internal heap before TLS 174196
[E][WiFiClientSecure.cpp:133] connect(): start_ssl_client: -1
[V][ssl_client.cpp:265] stop_ssl_socket(): Cleaning SSL connection.
Connected to api.telegram.org failed.
virtexultra
Beiträge: 127
Registriert: So 9. Dez 2018, 11:30

Re: Plattformio Arduino IDE Compilerproblem

Beitrag von virtexultra »

Dann liegt es wohl an den fehlenden Zertifikaten. Laut dem Code ist folgendes gegeben:
rootCABuff == NULL && pskIdent == NULL && psKey == NULL && !insecure => keine Zertifikate hinterlegt

Schaue dir doch Mal das Git Repo (https://github.com/espressif/arduino-es ... ientSecure) zu WiFiClientSecure an. Dort steht wie du ein Zertifikat hinterlegen kannst.
Benutzeravatar
Hightech
Beiträge: 11306
Registriert: So 11. Aug 2013, 18:37

Re: Plattformio Arduino IDE Compilerproblem

Beitrag von Hightech »

Das was mich irritiert ist, der selbe Code mit den gleichen Libs funktioniert mit der Arduino IDE.
Ich hab mir extra die TelegramCertificate.h mit dem Telegram Root Zertifikat direkt bei github geholt.
sirell
Beiträge: 606
Registriert: Mi 8. Apr 2015, 13:38
Wohnort: DE/Herzogenaurach

Re: Plattformio Arduino IDE Compilerproblem

Beitrag von sirell »

Prüfe nochmal deine Versionen. Es gab da unterschiedliche Ausgaben und Verwendung der Zertifikate zwischen 1.0.4 und 1.0.5.
Die IDEs haben jeweils eigene Versionen des ESP Cores eingebunden auch wenn die Libs in deinem Source identisch sind.

https://github.com/witnessmenow/Univers ... issues/228
beschreibt das und
https://github.com/witnessmenow/Univers ... -789991696
hat testcode der das Problem aufzeigt. Dieser Code muss in beiden IDEs fehlerfrei laufen. Dann klappt es auch mit anderen URLs.
Benutzeravatar
Hightech
Beiträge: 11306
Registriert: So 11. Aug 2013, 18:37

Re: Plattformio Arduino IDE Compilerproblem

Beitrag von Hightech »

Ich bin da etwas blöd für, ich hab mal ein Update gezogen, das ESP32 dev finde ich so nicht im PIO.

Hier der aktuelle Stand:

Code: Alles auswählen

Platform espressif32
--------
Updating platformio/espressif32               3.3.1                              [Up-to-date]
Updating platformio/toolchain-xtensa32        2.50200.97 @ ~2.50200.0            [Up-to-date]
Updating platformio/framework-arduinoespressif32 3.10006.210326 @ ~3.10006.0        [Up-to-date]
Updating platformio/tool-esptoolpy            1.30100.210531 @ ~1.30100.0        [Up-to-date]
Updating platformio/tool-openocd-esp32        2.1000.20210721 @ ~2.1000.0        [Up-to-date]
Updating platformio/tool-mkspiffs             2.230.0 @ ~2.230.0                 [Up-to-date]
virtexultra
Beiträge: 127
Registriert: So 9. Dez 2018, 11:30

Re: Plattformio Arduino IDE Compilerproblem

Beitrag von virtexultra »

Ich denke folgender Commit ist für die Verhaltensänderung verantwortlich:
https://github.com/espressif/arduino-es ... 7a49ef4957

Somit sind alle Versionen ab 1.0.5-rc5 betroffen. DeinPlatformIO nutzt 1.0.6.
Benutzeravatar
Hightech
Beiträge: 11306
Registriert: So 11. Aug 2013, 18:37

Re: Plattformio Arduino IDE Compilerproblem

Beitrag von Hightech »

virtexultra hat geschrieben: Fr 6. Aug 2021, 17:09 Ich denke folgender Commit ist für die Verhaltensänderung verantwortlich:
https://github.com/espressif/arduino-es ... 7a49ef4957

Somit sind alle Versionen ab 1.0.5-rc5 betroffen. DeinPlatformIO nutzt 1.0.6.
Oh, wo siehst du das ?
Mein Arduino IDE nutzt 1.0.4
Wo zum Geier finde ich das bei PIO?
virtexultra
Beiträge: 127
Registriert: So 9. Dez 2018, 11:30

Re: Plattformio Arduino IDE Compilerproblem

Beitrag von virtexultra »

Ich kann es nicht garantieren aber ich erkläre es mir so:

3.10006.210326
X.Y.Z
X = Hauptversion des Paketes, hier 3 da ESP-IDF in Version 3
Y = Versionsnummer des Paketes, in dem Fall mit Padding auf zwei Ziffern bei den Unterversionen
Z = Builddatum YYMMDD (und das stimmt mit dem Release im Git überein)
Benutzeravatar
Hightech
Beiträge: 11306
Registriert: So 11. Aug 2013, 18:37

Re: Plattformio Arduino IDE Compilerproblem

Beitrag von Hightech »

Es ist so wie Ihr sagt:
Die Version 1.0.4 funktioniert, die 1.0.5 und 1.0.6 funktionieren nicht, auch nicht in der Arduino IDE.

Wie bringe ich PIO jetzt bei, das er die 1.0.4 nutzt, oder kann ich das in der plattformio.ini irgenwie fixen?
Oder wie mache ich das ?
virtexultra
Beiträge: 127
Registriert: So 9. Dez 2018, 11:30

Re: Plattformio Arduino IDE Compilerproblem

Beitrag von virtexultra »

Sollte so möglich sein:
platform_packages = platformio/framework-arduinoespressif32 @ VERSION

Ich würde aber eher etwas in Richtung:

Code: Alles auswählen

#if ESP_ARDUINO_VERSION > ESP_ARDUINO_VERSION_VAL(1, 0, 5)
clientTCP.setCACert(TELEGRAM_CERTIFICATE_ROOT);
#endif
machen (ungetestet).
Benutzeravatar
Hightech
Beiträge: 11306
Registriert: So 11. Aug 2013, 18:37

Re: Plattformio Arduino IDE Compilerproblem

Beitrag von Hightech »

Ich habs jetzt gesehen:

Code: Alles auswählen

PACKAGES: 
 - framework-arduinoespressif32 3.10006.210326 (1.0.6) 
 - tool-esptoolpy 1.30100.210531 (3.1.0) 
 - toolchain-xtensa32 2.50200.97 (5.2.0)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Wenn ich das in der Ini so eintrage läuft es:

Code: Alles auswählen

[env:esp-wrover-kit]
platform = espressif32 @1.12.2
board = esp-wrover-kit
framework = arduino
monitor_speed = 115200
lib_deps = bblanchon/ArduinoJson@^6.18.3
build_flags = -DCORE_DEBUG_LEVEL=5
Benutzeravatar
Hightech
Beiträge: 11306
Registriert: So 11. Aug 2013, 18:37

Re: Plattformio Arduino IDE Compilerproblem

Beitrag von Hightech »

Danke für Eure Unterstützung!!!
Hätte ich niemals alleine gefunden.
Antworten