Hallo,
wenn ich in Blockly eine Funktion anlege in der ich die Werte des Feinstaubsensors SDS011 an openSenseMap schicken will, bekomme ich folgende Fehlermeldung:
{„exit“:„Command failed: 1: Uncaught Fatal Exception“,„process“:"/tmp/accdda8ffb162b883121133a1ec701be/sketch/sketch.ino: In function ‚void PublishOSM()‘:\n/tmp/accdda8ffb162b883121133a1ec701be/sketch/sketch.ino:121:33: error: ‚pm‘ was not declared in this scope\n addMeasurement(SENSOR_IDRID,pm.pm25);\n ^~\n/tmp/accdda8ffb162b883121133a1ec701be/sketch/sketch.ino:121:33: note: suggested alternative: ‚Pm‘\n addMeasurement(SENSOR_IDRID,pm.pm25);\n ^~\n Pm\n\nError during build: exit status 1\n"}
Hier der Blockly Code:
#include <senseBoxIO.h>
#include <WiFi101.h>
#include <SdsDustSensor.h> // http://librarymanager/All#Nova_Fitness_Sds_dust_sensors_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;
SdsDustSensor sds(Serial1);
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;
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)
;
}
}
/**
* Beschreibe diese Funktion …
*/
void PublishOSM() {
addMeasurement(SENSOR_IDRID,pm.pm25);
submitValues();
}
void setup() {
if (WiFi.status() == WL_NO_SHIELD) {
while (true);
}
while (status != WL_CONNECTED) {
status = WiFi.begin(ssid, pass);
delay(5000);
}
sds.begin();
sds.setQueryReportingMode();
ArduinoBearSSL.onGetTime(getTime);
}
void loop() {
time_startInterval = millis();
PmResult pm = sds.queryPm();
if (time_startInterval > time_actualInterval + intervalInterval) {
time_actualInterval = millis();
PublishOSM();
}
}