Hi all,
We are currently testing a library related to the IoT Platform with ESP32-WROOM-32 now.
_token is defined in .h file.
In one file HttpDownstream.cpp:
void HttpDownstreamClient::tokenCreate(char* URL, char* Subname, char* Suber, int expiretime) {
Serial.print("The subscription is associated with the Subscripter: ");
Serial.println(Suber);
StaticJsonDocument<200> root;
root["subscriber"] = Suber;
root["subscription"] = Subname;
root["expiresInMinutes"] = expiretime;
String body2send = "";
serializeJsonPretty(root, body2send);
if (_networkClient->connect(URL, 443)) {
Serial.println("Connected to the server to request token!");
// Make a HTTP request:
_networkClient->println("POST /notification2/token HTTP/1.1");
_networkClient->print("Host: ");
_networkClient->println(URL);
_networkClient->print("Authorization: Basic ");
_networkClient->println(_base64);
_networkClient->println("Content-Type: application/json");
_networkClient->print("Content-Length: ");
_networkClient->println(body2send.length());
_networkClient->println("Accept: application/json");
_networkClient->println();
_networkClient->println(body2send);
}
//Start to handle incoming message sent from server
while (_token.length() == 0) {
String msg = "";
while (_networkClient->available()) {
char c = _networkClient->read();
msg += c;
}
Serial.println("debug!!!");
Serial.println(msg);
int start_init = msg.indexOf("\"token\"");
int start = msg.indexOf(":",start_init);
int until_n = msg.indexOf("\"", start + 3);
Serial.println(until_n);
if (start != -1 && until_n != -1 ) {
_token = msg.substring(start + 2, until_n);
Serial.print("Token is: ");
Serial.println(_token);
}
}
}
In test.io we have:
void setup(){
//WiFi setting is not showed here
c8yclient.tokenCreate(host, SubscriptionName, SubscriberName, expiretime);
}
void loop()
{
while (wifisecure.available()) {
char c = wifisecure.read();
Serial.print(c);
}
}
What I get is something like this:
21:31:57.993 -> The subscription is associated with the Subscripter: Test2Sub1
21:31:58.033 -> Connected to the server to request token!
21:31:58.073 -> debug!!!
21:31:58.073 -> ⸮
21:31:58.073 -> -1
21:31:58.073 -> debug!!!
21:31:58.073 ->
21:31:58.073 -> -1
21:31:58.073 -> debug!!!
21:31:58.073 ->
21:31:58.073 -> -1
21:31:58.073 -> debug!!!
21:31:58.073 ->
21:31:58.073 -> -1
21:31:58.073 -> debug!!!
21:31:58.073 ->
21:31:58.073 -> -1
21:31:58.073 -> debug!!!
21:31:58.073 ->
21:31:58.073 -> -1
21:31:58.073 -> debug!!!
21:31:58.073 ->
21:31:58.073 -> -1
21:31:58.073 -> debug!!!
21:31:58.073 ->
21:31:58.073 -> -1
21:31:58.073 -> debug!!!
21:31:58.073 ->
21:31:58.073 -> -1
21:31:58.073 -> debug!!!
21:31:58.073 ->
21:31:58.073 -> -1
21:31:58.073 -> debug!!!
21:31:58.073 ->
21:31:58.073 -> -1
21:31:58.073 -> debug!!!
21:31:58.073 ->
21:31:58.073 -> -1
21:31:58.073 -> debug!!!
21:31:58.073 ->
21:31:58.073 -> -1
21:31:58.073 -> debug!!!
21:31:58.073 ->
21:31:58.073 -> -1
21:31:58.073 -> debug!!!
What I can make sure now is that the https request has been sent out. However, the incoming message from the server is not "well" processed. IMO there must be something wrong in memory since we have a "⸮" printed.
We tried this library with MKR wifi 1010, Arduino Uno rev 2 and nano 33 IoT. None of these boards has this issue. What has happened to ESP32? How can I fix this?
Many thanks in advance!