Keine Verbindung zur openSensemap


#1

Ich habe das Projekt Mobiler Datenlogger von Mario ausprobiert. Der erste Teil “Anzeige auf dem Display” klappt hervorragend. Nur die Verbindung zum opensSensemap-Server bleibt in einer Endlosschleife (Connecting…) hängen.
Hier mein Code:


/* Mobiler Datenlogger nach senseBox-Projekte
 *  V0.1 vom 10.5.2020
 */


#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include "SenseBoxMCU.h"

float Temperatur;
float Luftfeuchtigkeit;
float PM2_5;
float PM10;
float p10,p25;

const long interval = 10000;
long time_start = 0;
long time_actual = 0;

#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);
Bee* b = new Bee();
HDC1080 hdc;
const char SENSOR_IDCE9[] PROGMEM = "5eb7fd45d46fb8001b86d9dd";
const char SENSOR_IDCE8[] PROGMEM = "5eb7fd45d46fb8001b86d9dc";
const char SENSOR_IDCE7[] PROGMEM = "5eb7fd45d46fb8001b86d9db";
const char SENSOR_IDCE6[] PROGMEM = "5eb7fd45d46fb8001b86d9da";
static const uint8_t NUM_SENSORS = 4;
const char SENSEBOX_ID [] PROGMEM = "5eb7fd45d46fb8001b86d9d9";
const char server [] PROGMEM ="ingress.opensensemap.org";
WiFiSSLClient client;
typedef struct measurement {
    const char *sensorId;
    float value;
  } measurement;
char buffer[750];
measurement measurements[NUM_SENSORS];
  uint8_t num_measurements = 0;
const int lengthMultiplikator = 77;
GPS gps;
float latitude;
float longitude;
char* tsBuffer;
float height;

SDS011 my_sds(Serial1);


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


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


    void submitValues(float lat, float lng, float altitude, char* timeStamp) {
  if (client.connected()) {
    client.stop();
    delay(10);
  }
  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\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(lat, lng, altitude, timeStamp);
      // 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;
        }
      }

      num_measurements = 0;
      break;
    }
  }
}


void setup() {
  senseBoxIO.powerI2C(true);
delay(2000);
display.begin(SSD1306_SWITCHCAPVCC, 0x3D);
display.display();
delay(100);
display.clearDisplay();
  b->connectToWifi("ID","Kennwort");
delay(1000);
  hdc.begin();
  Serial1.begin(9600);
  gps.begin();
}

void loop() {

gps.getGPS();
latitude = gps.getLatitude();
longitude = gps.getLongitude();
tsBuffer = gps.getTimeStamp();
height = gps.getAltitude();
Temperatur = hdc.getTemperature();
  Luftfeuchtigkeit = hdc.getHumidity();
  PM2_5 = my_sds.getPm25();
  PM10 = my_sds.getPm10();
    display.setCursor(0,0);
    display.setTextSize(1);
    display.setTextColor(WHITE,BLACK);
    display.print("Temperatur:");
    display.println(Temperatur);
    display.setCursor(0,10);
    display.setTextSize(1);
    display.setTextColor(WHITE,BLACK);
    display.print("Feuchtigkeit:");
    display.println(Luftfeuchtigkeit);
    display.setCursor(0,20);
    display.setTextSize(1);
    display.setTextColor(WHITE,BLACK);
    display.print("PM:");
    display.println(PM2_5);
    display.setCursor(50,20);
    display.setTextSize(1);
    display.setTextColor(WHITE,BLACK);
    display.println(PM10);
  display.display();
  display.clearDisplay();
  time_start = millis();
  if (time_start > time_actual + interval) {
    time_actual = millis();
      addMeasurement(SENSOR_IDCE9,Temperatur);
      addMeasurement(SENSOR_IDCE8,Luftfeuchtigkeit);
      addMeasurement(SENSOR_IDCE7,PM2_5);
      addMeasurement(SENSOR_IDCE6,PM10);
    submitValues(latitude,longitude,height,tsBuffer);
  }

}

Im Code scheinen mir die Werte für den Server zu fehlen?