Skip to content

Commit

Permalink
v1.5.12
Browse files Browse the repository at this point in the history
 - removed commented code from merged PR
  • Loading branch information
matsfunk committed May 1, 2022
1 parent e557f8b commit ce81741
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 26 deletions.
Binary file modified dist/oocsi.zip
Binary file not shown.
36 changes: 21 additions & 15 deletions dist/oocsi/DFDataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand All @@ -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*/);
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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){
Expand All @@ -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);
}
2 changes: 1 addition & 1 deletion dist/oocsi/DFDataset.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions dist/oocsi/library.properties
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
name=OOCSI
version=1.5.11
version=1.5.12
author=Jort Band, Mathias Funk
maintainer=Mathias Funk <m.funk@tue.nl>
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
9 changes: 1 addition & 8 deletions src/DFDataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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);
}

0 comments on commit ce81741

Please sign in to comment.