Keine Verbindung über Wifi, obwohl mcu_component_test erfolgreich

wifi

#1

Hallo,
meine sensebox:home kann keine Verbindung zum Sensemap Server herstellen, obwohl die Tests, z.B. über mcu_component_test erfolgreich waren.
Bei Verwendung eines anderen WLAN, z.B. über Handy Hotspot ergibt sich das gleiche Ergebnis.
Inwiefern unetrscheidet sich die Wifi-Verbindungs-Testfunktion im mcu_component_test vom realen Verbindungsaufbau?

Woran kann es liegen?
Danke für Eure Hilfe, ich bin ratlos…

Testergebnis mit mcu_component_test:

Check WiFi firmware:
====================
Firmware version installed: 19.6.1
Latest firmware version available : 19.6.1

Check result: PASSED

Check internet connectivity:
============================
Connecting to WiFi...connected!
Calling openSenseMap server...connected!
Server response:

HTTP/1.1 200 OK
Accept-Ranges: bytes
Content-Length: 49
Content-Type: text/plain; charset=utf-8
Date: Sat, 18 Apr 2020 12:53:06 GMT
Connection: close

Connection successful! / Verbindung erfolgreich!

Disconnecting from server.
Disconnecting from WiFi.

und dann mit dem Sensebox sketch:

xbee1 spi enable...done
xbee1 power on...done
Attempting to connect to SSID: EADD35
Waiting 10 seconds for connection...done.

Scanning...
TSL45315 found.
VEML6070 found.
HDC1080 found.
4 sensors found.

Initializing sensors...
Initializing sensors done!
Starting loop in 3 seconds.
Starting new measurement...
Submit values
connecting...
connecting...
connection failed. Restarting System.

#2

Könntest Du mal den Sketch schicken, mit dem Du diese Probleme hast?


#3

Danke für deine Hilfe.
Es sollte der Standardsketch sein. Bei xxxx steht der WLAN Login.

/*
  senseBox:home - Citizen Sensingplatform
  Version: wifiv2_0.3
  Date: 2019-12-06
  Homepage: https://www.sensebox.de https://www.opensensemap.org
  Author: Reedu GmbH & Co. KG
  Note: Sketch for senseBox:home WiFi MCU Edition with dust particle upgrade
  Model: homeV2WifiFeinstaub
  Email: support@sensebox.de
  Code is in the public domain.
  https://github.com/sensebox/node-sketch-templater
*/

#include <senseBoxIO.h>
#include <WiFi101.h>
#include <SPI.h>
#include <Wire.h>

#include <Adafruit_Sensor.h>
#include <Adafruit_HDC1000.h>
#include <Adafruit_BMP280.h>
#include <Adafruit_BME680.h>
#include <Makerblog_TSL45315.h>
#include <VEML6070.h>
#include <SDS011-select-serial.h>

// Uncomment the next line to get debugging messages printed on the Serial port
// Do not leave this enabled for long time use
#define ENABLE_DEBUG

#ifdef ENABLE_DEBUG
#define DEBUG(str) Serial.println(str)
#define DEBUG_ARGS(str,str1) Serial.println(str,str1)
#define DEBUG2(str) Serial.print(str)
#define DEBUG_WRITE(c) Serial.write(c)
#else
#define DEBUG(str)
#define DEBUG_ARGS(str,str1)
#define DEBUG2(str)
#define DEBUG_WRITE(c)
#endif

/* ------------------------------------------------------------------------- */
/* ------------------------------Configuration------------------------------ */
/* ------------------------------------------------------------------------- */

// Wifi Credentials
const char *ssid = "xxxx"; // your network SSID (name)
const char *pass = "xxxx"; // your network password

// Number of serial port the SDS011 is connected to. Either Serial1 or Serial2
#define SDS_UART_PORT (Serial2)

// Interval of measuring and submitting values in seconds
const unsigned int postingInterval = 60e3;

// address of the server to send to
const char server[] PROGMEM = "ingress.opensensemap.org";

// senseBox ID
const char SENSEBOX_ID[] PROGMEM = "5e9ac6c945f937001cd1e920";

// Number of sensors
// Change this number if you add or remove sensors
// do not forget to remove or add the sensors on opensensemap.org
static const uint8_t NUM_SENSORS = 6;

// Connected sensors
// Temperatur
#define HDC1080_CONNECTED
// rel. Luftfeuchte
#define HDC1080_CONNECTED
// Beleuchtungsstärke
#define TSL45315_CONNECTED
// UV-Intensität
#define VEML6070_CONNECTED
// PM10
#define SDS011_CONNECTED
// PM2.5
#define SDS011_CONNECTED

// sensor IDs
// Temperatur
const char TEMPERSENSOR_ID[] PROGMEM = "5e9ac6c945f937001cd1e926";
// rel. Luftfeuchte
const char RELLUFSENSOR_ID[] PROGMEM = "5e9ac6c945f937001cd1e925";
// Beleuchtungsstärke
const char BELEUCSENSOR_ID[] PROGMEM = "5e9ac6c945f937001cd1e924";
// UV-Intensität
const char UVINTESENSOR_ID[] PROGMEM = "5e9ac6c945f937001cd1e923";
// PM10
const char PM10SENSOR_ID[] PROGMEM = "5e9ac6c945f937001cd1e922";
// PM2.5
const char PM25SENSOR_ID[] PROGMEM = "5e9ac6c945f937001cd1e921";

WiFiSSLClient client;

//Load sensors / instances
#ifdef HDC1080_CONNECTED
  Adafruit_HDC1000 HDC = Adafruit_HDC1000();
#endif
#ifdef BMP280_CONNECTED
  Adafruit_BMP280 BMP;
#endif
#ifdef TSL45315_CONNECTED
  Makerblog_TSL45315 TSL = Makerblog_TSL45315(TSL45315_TIME_M4);
#endif
#ifdef VEML6070_CONNECTED
  VEML6070 VEML;
#endif
#ifdef SDS011_CONNECTED
  SDS011 SDS(SDS_UART_PORT);
#endif
#ifdef SMT50_CONNECTED
  #define SOILTEMPPIN 0
  #define SOILMOISPIN 1
#endif
#ifdef SOUNDLEVELMETER_CONNECTED
  #define SOUNDMETERPIN 0
#endif
#ifdef BME680_CONNECTED
  Adafruit_BME680 BME;
#endif

typedef struct measurement {
  const char *sensorId;
  float value;
} measurement;

measurement measurements[NUM_SENSORS];
uint8_t num_measurements = 0;

// buffer for sprintf
char buffer[750];

/* ------------------------------------------------------------------------- */
/* --------------------------End of Configuration--------------------------- */
/* ------------------------------------------------------------------------- */

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);
    DEBUG2(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
  }
  // close any connection before send a new request.
  // This will free the socket on the WiFi shield
  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) {
      DEBUG(F("Connection successful, transferring..."));
      // 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 * 35);
      DEBUG(buffer);

      // 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();
        DEBUG_WRITE(c);
        // if the server's disconnected, stop the client:
        if (!client.connected()) {
          DEBUG();
          DEBUG("disconnecting from server.");
          client.stop();
          break;
        }
      }

      DEBUG("done!");

      // reset number of measurements
      num_measurements = 0;
      break;
    }
    delay(1000);
  }

  if (connected == false) {
    // Reset durchführen
    DEBUG(F("connection failed. Restarting System."));
    delay(5000);
    noInterrupts();
    NVIC_SystemReset();
    while (1)
      ;
  }
}

void checkI2CSensors() {
  byte error;
  int nDevices = 0;
  byte sensorAddr[] = {41, 56, 57, 64, 118};
  DEBUG("\nScanning...");
  for (int i = 0; i < sizeof(sensorAddr); i++) {
    Wire.beginTransmission(sensorAddr[i]);
    error = Wire.endTransmission();
    if (error == 0) {
      nDevices++;
      switch (sensorAddr[i])
      {
        case 0x29:
          DEBUG("TSL45315 found.");
          break;
        case 0x38: // &0x39
          DEBUG("VEML6070 found.");
          break;
        case 0x40:
          DEBUG("HDC1080 found.");
          break;
        case 0x76:
        #ifdef BMP280_CONNECTED
          DEBUG("BMP280 found.");
        #else
          DEBUG("BME680 found.");
        #endif
          break;
      }
    }
    else if (error == 4)
    {
      DEBUG2("Unknown error at address 0x");
      if (sensorAddr[i] < 16)
        DEBUG2("0");
      DEBUG_ARGS(sensorAddr[i], HEX);
    }
  }
  if (nDevices == 0) {
    DEBUG("No I2C devices found.\nCheck cable connections and press Reset.");
    while(true);
  } else {
    DEBUG2(nDevices);
    DEBUG(" sensors found.\n");
  }
  //return nDevices;
}

void setup() {
  // Initialize serial and wait for port to open:
  #ifdef ENABLE_DEBUG
    Serial.begin(9600);
  #endif
  delay(5000);

  DEBUG2("xbee1 spi enable...");
  senseBoxIO.SPIselectXB1(); // select XBEE1 spi
  DEBUG("done");
  senseBoxIO.powerXB1(false);delay(200);
  DEBUG2("xbee1 power on...");
  senseBoxIO.powerXB1(true); // power ON XBEE1
  DEBUG("done");
  senseBoxIO.powerI2C(false);delay(200);
  senseBoxIO.powerI2C(true);

  // Check WiFi Shield status
  if (WiFi.status() == WL_NO_SHIELD) {
    DEBUG(F("WiFi shield not present"));
    // don't continue:
    while (true)
      ;
  }
  uint8_t status = WL_IDLE_STATUS;
  // attempt to connect to Wifi network:
  while (status != WL_CONNECTED) {
    DEBUG2(F("Attempting to connect to SSID: "));
    DEBUG(ssid);
    // Connect to WPA/WPA2 network. Change this line if using open or WEP
    // network
    status = WiFi.begin(ssid, pass);
    // wait 10 seconds for connection:
    DEBUG2(F("Waiting 10 seconds for connection..."));
    delay(10000);
    DEBUG(F("done."));
  }

  #ifdef ENABLE_DEBUG
    // init I2C/wire library
    Wire.begin();
    checkI2CSensors();
  #endif

  // Sensor initialization
  DEBUG(F("Initializing sensors..."));
  #ifdef HDC1080_CONNECTED
    HDC.begin();
  #endif
  #ifdef BMP280_CONNECTED
    BMP.begin(0x76);
  #endif
  #ifdef VEML6070_CONNECTED
    VEML.begin();
    delay(500);
  #endif
  #ifdef TSL45315_CONNECTED
    TSL.begin();
  #endif
  #ifdef BME680_CONNECTED
    BME.begin(0x76);
    BME.setTemperatureOversampling(BME680_OS_8X);
    BME.setHumidityOversampling(BME680_OS_2X);
    BME.setPressureOversampling(BME680_OS_4X);
    BME.setIIRFilterSize(BME680_FILTER_SIZE_3);
  #endif
  #ifdef SDS011_CONNECTED
    SDS_UART_PORT.begin(9600);
  #endif
  DEBUG(F("Initializing sensors done!"));
  DEBUG(F("Starting loop in 3 seconds."));
  delay(3000);
}

void loop() {
  DEBUG(F("Starting new measurement..."));
  // capture loop start timestamp
  unsigned long start = millis();

  //-----Temperature-----//
  //-----Humidity-----//
  #ifdef HDC1080_CONNECTED
    addMeasurement(TEMPERSENSOR_ID, HDC.readTemperature());
    delay(200);
    addMeasurement(RELLUFSENSOR_ID, HDC.readHumidity());
  #endif

  //-----Pressure-----//
  #ifdef BMP280_CONNECTED
    float pressure;
    pressure = BMP.readPressure()/100;
    addMeasurement(LUFTDRSENSOR_ID, pressure);
  #endif

  //-----Lux-----//
  #ifdef TSL45315_CONNECTED
    addMeasurement(BELEUCSENSOR_ID, TSL.readLux()+1);  // 1 daz addiert
  #endif

  //-----UV intensity-----//
  #ifdef VEML6070_CONNECTED
    addMeasurement(UVINTESENSOR_ID, VEML.getUV());
  #endif

  //-----PM-----//
  #ifdef SDS011_CONNECTED
    uint8_t attempt = 0;
    float pm10, pm25;
    while (attempt < 5) {
      bool error = SDS.read(&pm25, &pm10);
      if (!error) {
        addMeasurement(PM10SENSOR_ID, pm10);
        addMeasurement(PM25SENSOR_ID, pm25);
        break;
      }
      attempt++;
    }
  #endif

  //-----Soil Temperature & Moisture-----//
  #ifdef SMT50_CONNECTED
    float voltage = analogRead(SOILTEMPPIN) * (3.3 / 1024.0);
    float soilTemperature = (voltage - 0.5) * 100;
    addMeasurement(BODENTSENSOR_ID, soilTemperature);
    voltage = analogRead(SOILMOISPIN) * (3.3 / 1024.0);
    float soilMoisture = (voltage * 50) / 3;
    addMeasurement(BODENFSENSOR_ID, soilMoisture);
  #endif

  //-----dB(A) Sound Level-----//
  #ifdef SOUNDLEVELMETER_CONNECTED
    float v = analogRead(SOUNDMETERPIN) * (3.3 / 1024.0);
    float decibel = v * 50;
    addMeasurement(LAUTSTSENSOR_ID, decibel);
  #endif

  //-----BME680-----//
  #ifdef BME680_CONNECTED
    BME.setGasHeater(0, 0);
    if( BME.performReading()) {
       addMeasurement(LUFTTESENSOR_ID, BME.temperature-1);
       addMeasurement(LUFTFESENSOR_ID, BME.humidity);
       addMeasurement(ATMLUFSENSOR_ID, BME.pressure/100);
    }
    BME.setGasHeater(320, 150); // 320*C for 150 ms
    if( BME.performReading()) {
       addMeasurement(VOCSENSOR_ID, BME.gas_resistance / 1000.0);
    }
  #endif

  DEBUG(F("Submit values"));
  submitValues();

  // schedule next round of measurements
  for (;;) {
    unsigned long now = millis();
    unsigned long elapsed = now - start;
    if (elapsed >= postingInterval)
      return;
  }
}

#4

Hallo @Markus,
bist du schon weiter mit dem Thema? Ich stehe gerade vor gefühlt exakt vor dem gleichen Problem.
Deshalb denke ich, es ist eher prinzipieller Natur.

Sorry das ich keine Lösung für dich habe!

Grüße, Barney.


#5

nein, leider nicht.
Ich möchte noch einen Versuch machen, nämlich die Wifi Firmware downzugraden auf 19.5.4. Ich habe Version 19.6.1 und habe irgendwo den Hinweis gelesen, dass das bei jemandem geholfen habe. Unerklärlich ist mir damit aber immer noch der Widerspruch zum erfolgreichen mcu_component_test.


#6

ja bin ich auch gerade dran und habe auch 19.6.1. Nur leider hängt der Test connection bei 50 % und kommt nicht weiter voran. Habe massive Problem mit dem Port, der verschwindet immer wieder und das möchte ich jetzt eigentlich nicht während dem Firmware-Update machen.

Viel Erfolg dir!


#7

so, bei mir läuft es.
Fazit:

  • ein funktionierender MCU_component_test ist derzeit nicht ausreichend.
  • Wenn der Port COM3 ständig wieder verschwindet, lohnt es sich, ihn im Gerätemanager zu deinstallieren und die Treiber neu zu installieren. Dann hat’s zumindest für das Firmware downgrade gereicht. Im [Gerätemanager unter Ansicht-> Verborgene Anzeigen hilft bei der Suche des Ports.]
  • für die WiFi Anbindung funktioniert Version 19.6.1 aktuell nicht. Downgraden hilft, also nicht mindestens Version 19.5.4 sondern vermutlich genau 19.5.4.
  • Hier noch Link für die Firmware Anleitung:
    https://sensebox.github.io/books-v2/home/de/additional-info.html

Gruß
Barney


#8

I also had many problems connecting the wifi to opensense.org. My mcu_component_test showed sensor readings and indicated I was connected both to wifi and opensense, but I could not upload data to the map app.

I, too had wifi firmware 19.6.1 and I figured this was the problem. But I was unable to “upgrade” (downgrade) using the Updater because “the programmer was not processing”.

When running skteches I encountered a suite of errors including:

  • WARNING: library SDS011-select-serial claims to run on (esp8266, avr) architecture(s) and may be incompatible with your current board which runs on (samd) architecture(s).
  • java.io.IOException: jssc.SerialPortException: Port name - COM4; Method name - setEventsMask(); Exception type - Can’t set mask.
    at processing.app.Serial.dispose(Serial.java:166)
    at processing.app.SerialMonitor.close(SerialMonitor.java:116)
    at processing.app.AbstractMonitor.suspend(AbstractMonitor.java:90)
    at processing.app.Editor$DefaultExportHandler.run(Editor.java:2020)
    at java.lang.Thread.run(Thread.java:748)
  • Caused by: jssc.SerialPortException: Port name - COM4; Method name - setEventsMask(); Exception type - Can’t set mask.

To get the updater running and downgrade the firmware I tried all of the following:

  • running IDE as administrator
  • allowing arduino to pass through the firewall
  • re-installing windows zip to make sure I enabled java for all networks
  • removing windows zipfile installation from computer and registry and installing the windows installer. exe version

Ultimately, through some combination of factors above, I was able to get the wifi firmware downgraded to 19.5.4. After that, my data appeared on opensensemap.

Cheers,
Anne


#9

Das gleiche Problem hab ich auch


#10

Ich hatte das selbe Problem: Verbindungstest beim mcu_component_test war erfolgreich, beim Ausführen des richtigen Sketches: Keine Verbindung zum opensensemap Server.

Ursache war bei mir das SSL-Zertifikat, das von ingress.opensensemap.org verwendet wird.
Der mcu_component_test verbindet sich unverschlüsselt über http, klappt wunderbar. Der richtige Sketch verwendet dann https und vertraut aber dem von ingress.opensensemap.org verwendeten Zertifikat nicht (Ausgestellt von Let’s Encrypt).

Geholfen hat bei mir dann das Zertifikat als vertrauenswürdig der Sensebox hinzuzufügen.
Das geht in der Arduino IDE über Tools -> WiFi101 / WiFiNINA Firmware updater und dann unten im Bereich “3. Update SSL root certificates”.