MQTT Communication
Smart Factory
myJSON.cpp
Go to the documentation of this file.
1 
14 #include "myJSON.h"
15 
16 myJSON::myJSON(const size_t ParsCapacity) : pParsCapacity(ParsCapacity) {
17 }
18 
20  DBFUNCCALLln("myJSON::parsingJSONToStruct(const char* json)");
21  DBINFO3ln(json);
22  myJSONStr tempStr;
23  DynamicJsonDocument doc(pParsCapacity);
24 
25  DeserializationError error = deserializeJson(doc, json);
26  if (error) {
27  DBWARNING("deserializeJson() failed: ");
28  DBWARNINGln(error.c_str());
29  tempStr.id = "Pars failed";
30  return tempStr;
31  } else {
32  // DBINFO1("deserializeJson() success: ");
33  /* use excplicit cast to prevent ambiguity
34  * https://arduinojson.org/v6/doc/deserialization/ S67
35  */
36 
37  tempStr.id = doc["id"].as<String>(); // "SV46465"
38  tempStr.status = doc["status"].as<String>(); // "driving"
39  tempStr.sector = doc["sector"].as<String>(); // "sector"
40  tempStr.line = doc["line"].as<int>(); // 1
41  tempStr.ack = doc["ack"].as<String>(); // "hostname"
42  tempStr.req = doc["req"].as<String>(); // "hostname"
43  tempStr.cargo = doc["cargo"].as<String>(); // "gemuse"
44  tempStr.token = doc["token"].as<bool>(); // false
45  tempStr.error = doc["error"].as<bool>(); // false
46  return tempStr;
47  }
48 }
49 
50 //Serializing program ===================================================
51 // String myJSON::serializ(myJSONStr tempStr) {
52 // // DynamicJsonDocument doc(pSerializCapacity);
53 
54 // // doc["urgent"] = tempStr.urgent;
55 // // doc["topic"] = tempStr.topic;
56 // // doc["hostname"] = tempStr.hostname;
57 // // doc["request"] = tempStr.request;
58 // // doc["level"] = tempStr.level;
59 
60 // // JsonArray vehicleParams = doc.createNestedArray("vehicleParams");
61 // // vehicleParams.add(tempStr.vehicleParams);
62 // // // vehicleParams.add(tempStr.vehicleParams[0]);
63 // // // vehicleParams.add(tempStr.vehicleParams[1]));
64 // // // vehicleParams.add(tempStr.vehicleParams[2]));
65 // // // vehicleParams.add(tempStr.vehicleParams[3]));
66 // // // vehicleParams.add(tempStr.vehicleParams[4]));
67 
68 // // serializeJson(doc, Serial);
69 // // // serializeJsonPretty(doc, Serial);
70 // }
String req
Request.
Definition: myJSONStr.h:40
myJSON class handels the conversion from the JSON-Format into a struct
myJSON Struct defines the format of the messages
Definition: myJSONStr.h:33
const size_t pParsCapacity
Definition: myJSON.h:51
String cargo
Cargo.
Definition: myJSONStr.h:41
int line
Line.
Definition: myJSONStr.h:38
myJSON(const size_t ParsCapacity)
Construct a new myJSON object.
Definition: myJSON.cpp:16
bool error
Error-token.
Definition: myJSONStr.h:43
String status
Status.
Definition: myJSONStr.h:36
String id
Hostname.
Definition: myJSONStr.h:34
String sector
Sector.
Definition: myJSONStr.h:37
myJSONStr parsingJSONToStruct(const char *json)
Parsing JSON-Format into myJSONStr.
Definition: myJSON.cpp:19
String ack
Acknoledgement.
Definition: myJSONStr.h:39
bool token
Gateway and Reset-token.
Definition: myJSONStr.h:42