Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: MQTTSN mbed-http
sensor.h
00001 #include <string> 00002 void process_rsc(MbedJSONValue &MSG); 00003 00004 bool reg_resp = false; 00005 00006 char* CSE_ID = "cse1"; 00007 char* AE_ID; 00008 00009 struct Mendatory 00010 { 00011 string To; 00012 string From; 00013 string Request_Identifier; 00014 int Operation; 00015 int Resource_Type; 00016 }m1; 00017 00018 struct CreateAE 00019 { 00020 string resourceName; 00021 string App_ID; 00022 string pointOfAccess; 00023 bool requestReachability; 00024 }CAE; 00025 00026 const char* Create_AE() 00027 { 00028 MbedJSONValue MSG, demo, demo2, demo3; 00029 00030 std::string s; 00031 00032 //fill the object 00033 00034 demo3["api"] = CAE.App_ID; 00035 demo3["rn"] = CAE.resourceName; 00036 demo3["rr"] = CAE.requestReachability; 00037 demo2["m2m:ae"] = demo3; 00038 demo["fr"] = m1.From; 00039 demo["op"] = m1.Operation; 00040 demo["pc"] = demo2; 00041 demo["rqi"] = m1.Request_Identifier; 00042 demo["to"] = m1.To; 00043 demo["ty"] = m1.Resource_Type; 00044 00045 //serialize it into a JSON string 00046 s = demo.serialize(); 00047 printf("\nMSG SIZE: %d\n", s.length()); 00048 //printf("json: %s\r\n", s.c_str()); 00049 return s.c_str(); 00050 } 00051 00052 void process_msg() 00053 { 00054 MbedJSONValue MSG; 00055 //printf("Before Parsing\n"); 00056 parse(MSG, messageBuffer); 00057 //bool temp; //Check fot parameters presence 00058 00059 ////////////////////////resource Type Parameter (Mendatory parameter)////////////////////// 00060 if(MSG.hasMember("rsc")) 00061 { 00062 rsc = MSG["rsc"].get<int>(); 00063 printf("Response Status Code: %d\r\n", rsc); 00064 Response_Type(); 00065 printf("Response Status: %s\r\n", response.c_str()); 00066 process_rsc(MSG); 00067 return; 00068 } 00069 00070 ////////////////////////resource Type Parameter (Mendatory parameter)////////////////////// 00071 if(MSG.hasMember("ty")) 00072 { 00073 ty = MSG["ty"].get<int>(); 00074 printf("ResourceType: %d\r\n", ty); 00075 resource_type(); 00076 printf("ResourceType: %s\r\n", resourceType.c_str()); 00077 } 00078 else { 00079 //add response code for no mendatory parameter 00080 return; } 00081 00082 ////////////////////////From parameter (Mendatory parameter[optional for Create AE])////////// 00083 if(MSG.hasMember("fr")) 00084 { 00085 From = MSG["fr"].get<std::string>(); 00086 printf("From: %s\r\n", From.c_str()); 00087 } 00088 else { 00089 //add Response Status Code for no mendatory parameter BAD_REQUEST 00090 return; } 00091 00092 ////////////////////////Operation Parameter (Mendatory parameter)////////////////////// 00093 if(MSG.hasMember("op")) 00094 { 00095 op = MSG["op"].get<int>(); 00096 printf("Operation: %d\r\n", op); 00097 Operation_Type(); 00098 printf("Operation: %s\r\n", operation.c_str()); 00099 } 00100 else { 00101 //add response code for no mendatory parameter 00102 return; } 00103 00104 ////////////////////////To Parameter (Mendatory parameter)////////////////////// 00105 if(MSG.hasMember("to")) 00106 { 00107 to = MSG["to"].get<std::string>(); 00108 printf("To: %s\r\n", to.c_str()); 00109 } 00110 else { 00111 //add response code for no mendatory parameter 00112 return; } 00113 00114 ////////////////////////Request Identifier (Mendatory parameter)////////////////////// 00115 if(MSG.hasMember("rqi")) 00116 { 00117 rqi = MSG["rqi"].get<std::string>(); 00118 printf("Request Identifier: %s\r\n", rqi.c_str()); 00119 } 00120 else { 00121 //add response code for no mendatory parameter 00122 return; } 00123 00124 ////////////////////////Response Status Code 00125 if(MSG.hasMember("rsc")) 00126 { 00127 rsc = MSG["rsc"].get<int>(); 00128 printf("Response Status Code: %d\r\n", rsc); 00129 Response_Type(); 00130 printf("Response Status: %s\r\n", response.c_str()); 00131 } 00132 MbedJSONValue &MSG_1 = MSG["pc"][content]; //content value depends on the resource type e.g. m2m:ae for resource type 2 00133 00134 //////////////////////// Resource specific attributes CSE-ID 00135 if(MSG_1.hasMember("csi")) 00136 { 00137 csi = MSG_1["csi"].get<std::string>(); 00138 printf("CSI: %s\r\n", csi.c_str()); 00139 } 00140 00141 //////////////////////// Resource specific attributes Point of Access 00142 if(MSG_1.hasMember("poa")) 00143 { 00144 poa = MSG_1["poa"].get<std::string>(); 00145 printf("POA: %s\r\n", poa.c_str()); 00146 } 00147 00148 /////////////////////// Resource specific attributes CSE Type 00149 if(MSG_1.hasMember("cst")) 00150 { 00151 cst = MSG_1["cst"].get<int>(); 00152 printf("CSE Type: %d\r\n", cst); 00153 CSE_Type(); 00154 printf("CSE Type: %s\r\n", cseType.c_str()); 00155 } 00156 00157 /////////////////////// Resource specific attributes RequestReachability 00158 if(MSG_1.hasMember("rr")) 00159 { 00160 RequestReachability = MSG_1["rr"].get<bool>(); 00161 printf("RR: %s\r\n", RequestReachability? "true" : "false"); 00162 } 00163 00164 /////////////////////// Resource specific attributes App-ID 00165 if(MSG_1.hasMember("api")) 00166 { 00167 api = MSG_1["api"].get<std::string>(); 00168 printf("App-ID: %s\r\n", api.c_str()); 00169 } 00170 // msg[0] = '\0'; 00171 //MSG.~MbedJSONValue(); 00172 //MSG_1.~MbedJSONValue();*/ 00173 } 00174 00175 void process_rsc(MbedJSONValue &MSG) 00176 { 00177 if(MSG.hasMember("rqi")) 00178 { 00179 rqi = MSG["rqi"].get<std::string>(); 00180 printf("Request Identifier: %s\r\n", rqi.c_str()); 00181 } 00182 else { 00183 //add response code for no mendatory parameter 00184 return; } 00185 if(MSG.hasMember("to")) 00186 { 00187 to = MSG["to"].get<std::string>(); 00188 printf("To: %s\r\n", to.c_str()); 00189 } 00190 else { 00191 //add response code for no mendatory parameter 00192 return; } 00193 if(MSG.hasMember("fr")) 00194 { 00195 From = MSG["fr"].get<std::string>(); 00196 printf("From: %s\r\n", From.c_str()); 00197 } 00198 else { 00199 //add response code for no mendatory parameter 00200 return; } 00201 00202 MbedJSONValue &MSG_1 = MSG["pc"][content]; 00203 00204 if(MSG_1.hasMember("ty")) 00205 { 00206 ty = MSG_1["ty"].get<int>(); 00207 printf("ResourceType: %d\r\n", ty); 00208 resource_type(); 00209 printf("ResourceType: %s\r\n", resourceType.c_str()); 00210 } 00211 else { 00212 //add response code for no mendatory parameter 00213 return; } 00214 00215 if(MSG_1.hasMember("rr")) 00216 { 00217 RequestReachability = MSG_1["rr"].get<bool>(); 00218 printf("RR: %s\r\n", RequestReachability? "true" : "false"); 00219 } 00220 if(MSG_1.hasMember("aei")) 00221 { 00222 aei = MSG_1["aei"].get<std::string>(); 00223 printf("AE_ID: %s\r\n", aei.c_str()); 00224 } 00225 if(MSG_1.hasMember("poa")) 00226 { 00227 poa = MSG_1["poa"].get<std::string>(); 00228 printf("POA: %s\r\n", poa.c_str()); 00229 } 00230 if(MSG_1.hasMember("rn")) 00231 { 00232 rn = MSG_1["rn"].get<std::string>(); 00233 printf("Resource Name: %s\r\n", rn.c_str()); 00234 } 00235 if(MSG_1.hasMember("api")) 00236 { 00237 api = MSG_1["api"].get<std::string>(); 00238 printf("App-ID: %s\r\n", api.c_str()); 00239 } 00240 return; 00241 }
Generated on Thu Jul 14 2022 08:11:13 by
1.7.2