Fehler beim kompilieren in Blockly (WiFi Client)

Hallo,

ich möchte meine Sensebox gerne so einrichten, dass sie die Daten sowohl an openSenseMap, als auch via MQTT im lokalen Netzwerk veröffentlich. Leider bekomme ich beim Kompilieren die Fehlermeldung:

{„exit“:„Command failed: 1: Uncaught Fatal Exception“,„process“:"/tmp/a8fe5f89952bdf67cabf1dad0880ba3a/sketch/sketch.ino:29:32: error: conflicting declaration ‚BearSSLClient client‘\n BearSSLClient client(wifiClient);\n ^\n/tmp/a8fe5f89952bdf67cabf1dad0880ba3a/sketch/sketch.ino:21:12: note: previous declaration as ‚WiFiClient client‘\n WiFiClient client;\n ^~~~~~\n\nError during build: exit status 1\n"}

Hier noch der Blockly-Code:

#include <senseBoxIO.h>
#include <WiFi101.h>
#include <Adafruit_MQTT.h> //http://librarymanager/All#Adafruit_MQTT_Library"
#include <Adafruit_MQTT_Client.h>
#include <Adafruit_HDC1000.h> // http://librarymanager/All#Adafruit_HDC1000_Library
#include <ArduinoBearSSL.h>
#include <ArduinoECCX08.h>

char ssid[] = "SSID";
char pass[] = "Password";
int status = WL_IDLE_STATUS;

  const long intervalInterval = 10000;
  long time_startInterval = 0;
  long time_actualInterval = 0;

#define SERVER      "io.adafruit.com"
#define SERVERPORT      1883
#define USERNAME      "Username"
#define PASS      "Password"
WiFiClient client;
Adafruit_MQTT_Client mqtt(&client, SERVER, SERVERPORT, USERNAME, PASS);
Adafruit_HDC1000 hdc = Adafruit_HDC1000();
const char SENSOR_IDRID[] PROGMEM = "sensorID";
static const uint8_t NUM_SENSORS = 1;
const char SENSEBOX_ID [] PROGMEM = "senseBox ID";
const char server [] PROGMEM ="ingress.opensensemap.org";
WiFiClient wifiClient;
BearSSLClient client(wifiClient);
typedef struct measurement {
      const char *sensorId;
      float value;
    } measurement;
char buffer[750];
measurement measurements[NUM_SENSORS];
    uint8_t num_measurements = 0;
const int lengthMultiplikator = 35;
Adafruit_MQTT_Publish Name = Adafruit_MQTT_Publish(&mqtt, USERNAME "/feeds/Name");

// Function to connect and reconnect as necessary to the MQTT server.
    // Should be called in the loop function and it will take care if connecting.
void MQTT_connect() {
      int8_t ret;
      // Stop if already connected.
      if (mqtt.connected()) {
        return;
      }
      while ((ret = mqtt.connect()) != 0) { // connect will return 0 for connected
           mqtt.disconnect();
           delay(5000);  // wait 5 seconds
      }
}


unsigned long getTime() {
      return WiFi.getTime();
    }

    void addMeasurement(const char *sensorId, float value) {
    measurements[num_measurements].sensorId = sensorId;
    measurements[num_measurements].value = value;
    num_measurements++;
    }

    void writeMeasurementsToClient() {
    // iterate throug the measurements array
    for (uint8_t i = 0; i < num_measurements; i++) {
      sprintf_P(buffer, PSTR("%s,%9.2f\n"), measurements[i].sensorId,
                measurements[i].value);
      // transmit buffer to client
      client.print(buffer);
    }
    // reset num_measurements
    num_measurements = 0;
  }

  void submitValues() {
if (WiFi.status() != WL_CONNECTED) {
WiFi.disconnect();
delay(1000); // wait 1s
WiFi.begin(ssid, pass);
delay(5000); // wait 5s
}
  if (client.connected()) {
      client.stop();
      delay(1000);
    }
  bool connected = false;
  char _server[strlen_P(server)];
  strcpy_P(_server, server);
  for (uint8_t timeout = 2; timeout != 0; timeout--) {
    Serial.println(F("connecting..."));
    connected = client.connect(_server, 443);
    if (connected == true) {
      // construct the HTTP POST request:
      sprintf_P(buffer,
                PSTR("POST /boxes/%s/data HTTP/1.1\nAuthorization: access_token\nHost: %s\nContent-Type: "
                     "text/csv\nConnection: close\nContent-Length: %i\n\n"),
                SENSEBOX_ID, server, num_measurements * lengthMultiplikator);
      // send the HTTP POST request:
      client.print(buffer);
      // send measurements
      writeMeasurementsToClient();
      // send empty line to end the request
      client.println();
      uint16_t timeout = 0;
      // allow the response to be computed
      while (timeout <= 5000) {
        delay(10);
        timeout = timeout + 10;
        if (client.available()) {
          break;
        }
      }

      while (client.available()) {
        char c = client.read();
        // if the server's disconnected, stop the client:
        if (!client.connected()) {
          client.stop();
          break;
        }
      }

      num_measurements = 0;
      break;
    }
    delay(1000);
  }

  if (connected == false) {
  delay(5000);
  noInterrupts();
 NVIC_SystemReset();
 while (1)
 ;
 }
  }


void setup() {

if (WiFi.status() == WL_NO_SHIELD) {
    while (true);
}
while (status != WL_CONNECTED) {
    status = WiFi.begin(ssid, pass);
    delay(5000);
}

hdc.begin();
ArduinoBearSSL.onGetTime(getTime);



}


void loop() {
time_startInterval = millis();

MQTT_connect();

  if (time_startInterval > time_actualInterval + intervalInterval) {
  time_actualInterval = millis();
    addMeasurement(SENSOR_IDRID,hdc.readHumidity());
  submitValues();
  Name.publish(hdc.readHumidity());}

}

sollte hier behoben sein: https://deploy-preview-272--blockly-react.netlify.app/

1 Like