diff --git a/dist/oocsi.zip b/dist/oocsi.zip index 9ba6184..835fe80 100644 Binary files a/dist/oocsi.zip and b/dist/oocsi.zip differ diff --git a/dist/oocsi/DFDataset.cpp b/dist/oocsi/DFDataset.cpp index 99e8941..26db6c0 100644 --- a/dist/oocsi/DFDataset.cpp +++ b/dist/oocsi/DFDataset.cpp @@ -20,6 +20,11 @@ DFDataset::DFDataset(const char* server, int id, const char* token) { api_token = token; logging = true; jsonMessage.clear(); + + device_id = NULL; + activity_id = NULL; + resource_id = NULL; + resource_token = NULL; } // iot datasets @@ -80,12 +85,13 @@ bool DFDataset::logItem() { device_id = device_id != NULL ? device_id : ""; // url encode activity id string because it will be part of the URL - activity_id = urlencode(activity_id); + char activity_id_url[200]; + urlencode(activity_id_url, activity_id); // do transmission #if defined(ARDUINO_SAMD_MKRWIFI1010) || defined(ARDUINO_AVR_UNO_WIFI_REV2) || defined(ARDUINO_SAMD_NANO_33_IOT) || defined(ARDUINO_NANO_RP2040_CONNECT) // compile address - snprintf_P(address, sizeof(address), PSTR("/datasets/ts/log/%i/%s"), dataset_id, activity_id); + snprintf_P(address, sizeof(address), PSTR("/datasets/ts/log/%i/%s"), dataset_id, activity_id_url); HttpClient http = HttpClient(wifi, host, 80); http.beginRequest(); @@ -107,7 +113,7 @@ bool DFDataset::logItem() { return httpCode == 200; #else // compile address - snprintf_P(address, sizeof(address), PSTR("http://%s/datasets/ts/log/%i/%s"), host, dataset_id, activity_id); + snprintf_P(address, sizeof(address), PSTR("http://%s/datasets/ts/log/%i/%s"), host, dataset_id, activity_id_url); HTTPClient http; http.begin(wifi, address/*, root_ca_df*/); @@ -318,7 +324,7 @@ bool DFDataset::getItem() { http.print(""); http.endRequest(); - int httpCode = http.responseStatusCode(); + /*int httpCode = */http.responseStatusCode(); String jsonResponse = http.responseBody(); //http.end(); @@ -488,17 +494,17 @@ void DFDataset::setLogging(bool log) { logging = log; } -const char* DFDataset::urlencode(const char* str) +void DFDataset::urlencode(char* dst, const char* src) { - String encodedString=""; + char encodedString[200] = ""; char c; char code0; char code1; - char code2; - for (int i =0; i < strlen(str); i++){ - c=str[i]; + + for (int i =0; i < strlen(src); i++){ + c=src[i]; if (isalnum(c)){ - encodedString+=c; + sprintf(encodedString, "%s%c", encodedString, c); } else { code1=(c & 0xf)+'0'; if ((c & 0xf) >9){ @@ -509,12 +515,12 @@ const char* DFDataset::urlencode(const char* str) if (c > 9){ code0=c - 10 + 'A'; } - code2='\0'; - encodedString+='%'; - encodedString+=code0; - encodedString+=code1; + sprintf(encodedString, "%s%c", encodedString, '%'); + sprintf(encodedString, "%s%c", encodedString, code0); + sprintf(encodedString, "%s%c", encodedString, code1); } yield(); } - return encodedString.c_str(); + + strcpy(dst, encodedString); } diff --git a/dist/oocsi/DFDataset.h b/dist/oocsi/DFDataset.h index ee0a551..a3d2f10 100644 --- a/dist/oocsi/DFDataset.h +++ b/dist/oocsi/DFDataset.h @@ -109,7 +109,7 @@ class DFDataset { void println(); void println(const String &message); void println(char message); - const char* urlencode(const char* str); + void urlencode(char* dst, const char* src); }; #endif diff --git a/dist/oocsi/library.properties b/dist/oocsi/library.properties index d2bd2cd..6476587 100644 --- a/dist/oocsi/library.properties +++ b/dist/oocsi/library.properties @@ -1,11 +1,11 @@ name=OOCSI -version=1.5.11 +version=1.5.12 author=Jort Band, Mathias Funk maintainer=Mathias Funk sentence=OOCSI client library for the ESP32, ESP8266, Arduino MKR Wifi 101, Arduino UNO Wifi, Arduino Nano 33 IoT, and Arduino Nano RP2040 paragraph=Library for easy connection and communication with the ESP32, ESP8266 and Arduino NANO 33 IoT modules over the OOCSI platform category=Communication url=https://github.com/iddi/oocsi-esp -architectures=esp32,esp8266,samd,megaavr,mbed_nano,mbed_rp2040 +architectures=esp32,esp8266,samd,megaavr,mbed_nano,mbed_rp2040,rp2040 includes=OOCSI.h depends=ArduinoJson,ArduinoHttpClient \ No newline at end of file diff --git a/src/DFDataset.cpp b/src/DFDataset.cpp index 7b08515..26db6c0 100644 --- a/src/DFDataset.cpp +++ b/src/DFDataset.cpp @@ -497,15 +497,13 @@ void DFDataset::setLogging(bool log) { void DFDataset::urlencode(char* dst, const char* src) { char encodedString[200] = ""; - //String encodedString=""; char c; char code0; char code1; - //char code2; + for (int i =0; i < strlen(src); i++){ c=src[i]; if (isalnum(c)){ - // encodedString+=c; sprintf(encodedString, "%s%c", encodedString, c); } else { code1=(c & 0xf)+'0'; @@ -517,17 +515,12 @@ void DFDataset::urlencode(char* dst, const char* src) if (c > 9){ code0=c - 10 + 'A'; } - code2='\0'; - //encodedString+='%'; sprintf(encodedString, "%s%c", encodedString, '%'); - //encodedString+=code0; sprintf(encodedString, "%s%c", encodedString, code0); - //encodedString+=code1; sprintf(encodedString, "%s%c", encodedString, code1); } yield(); } - //return encodedString.c_str(); strcpy(dst, encodedString); }