v1
Dependencies: MQTTSN mbed-http
Revision 15:557d0008dd2d, committed 2019-03-11
- Comitter:
- m_ahsan
- Date:
- Mon Mar 11 07:51:06 2019 +0000
- Parent:
- 14:e544557919d9
- Commit message:
- 123
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Client-AE.cpp Mon Mar 11 07:51:06 2019 +0000
@@ -0,0 +1,94 @@
+#define MQTTSNCLIENT_QOS2 1
+
+#include "mbed.h"
+#include "stdio.h"
+#include "MQTT_server_setting.h"
+#include "MQTTSNUDP.h"
+#include "MQTTSNClient.h"
+#include "MbedJSONValue.h"
+#include "Enumeration.h"
+#include "sensor.h"
+#include "easy-connect.h"
+#include "MQTTSN_func.h"
+#include "registration.h"
+
+NetworkInterface* network = NULL;
+
+int main() {
+
+ float version = 0.47;
+ MQTTSNUDP* ipstack = NULL;
+ MQTTSN::Client<MQTTSNUDP, Countdown> *client = NULL;
+
+ /////////////////////////////////////////////////////////////////////////////////////////
+ printf("Nai binary hai ye theek hai Opening network interface...\r\n");
+ {
+ network = easy_connect(true); // If true, prints out connection details.
+ if (!network) {
+ printf("Unable to open network interface.\r\n");
+ return -1;
+ }
+ }
+ printf("Network interface opened successfully.\r\n");
+ printf("\r\n");
+JUMP:
+ ipstack = new MQTTSNUDP(network);
+ //MQTTSNUDP ipstack = MQTTSNUDP(network);
+
+ const char* Local_IP = network->get_ip_address();
+ printf("IP Address of Device is: %s\n", Local_IP);
+
+ const char* Local_MAC = network->get_mac_address();
+ printf("MAC Address of Device is: %s\n", Local_MAC);
+
+ client = new MQTTSN::Client<MQTTSNUDP, Countdown>(*ipstack);
+ //////////////////////////////////UDP Connect///////////////////////////////////////////
+ printf("Connecting to %s:%d\n", MQTT_SERVER_HOST_NAME, PORT);
+ rc = ipstack->connect(MQTT_SERVER_HOST_NAME, PORT);
+ if (rc != 0)
+ printf("rc from UDP connect is %d\n", rc);
+ else
+ printf("UDP connected\n");
+ //////////////////////////////////MQTT Connect///////////////////////////////////////////
+ attemptConnect(client, ipstack);
+ Registration(client, ipstack);
+ while(1)
+ {
+ // Check connection //
+ if(!client->isConnected()){
+ break;
+ }
+ // Received a control message. //
+ if(isMessageArrived) {
+ isMessageArrived = false;
+ // Just print it out here.
+ //printf("\r\nMessage arrived:\r\n%s\r\n", messageBuffer);
+ //process_msg();
+ //free(messageBuffer);
+ }
+ // Publish data //
+ //PUB_Count++;
+
+ client->yield(4000);
+ //wait(4);
+
+ }
+
+ //if ((rc = client->unsubscribe(topicid2)) != 0)
+ // printf("rc from unsubscribe was %d\n", rc);
+
+ if ((rc = client->disconnect()) != 0)
+ printf("rc from disconnect was %d\n", rc);
+
+ ipstack->disconnect();
+
+ delete ipstack;
+ delete client;
+
+ printf("Version %.2f: finish %d msgs\n", version, arrivedcount);
+ printf("Finishing with %d messages received\n", arrivedcount);
+goto JUMP;
+
+ return 0;
+
+}
--- a/Client-main.cpp Mon Dec 10 08:06:33 2018 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,190 +0,0 @@
-/* SpwfInterface NetworkSocketAPI Example Program
- * Copyright (c) 2015 ARM Limited
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "mbed.h"
-#define MQTTSNCLIENT_QOS2 1
-//#include "TCPSocket.h"
-//#include "UDPSocket.h"
-#include "MQTTSNUDP.h"
-#include "MQTTSNClient.h"
-
-//
-
-//------------------------------------
-// Hyperterminal configuration
-// 9600 bauds, 8-bit data, no parity
-//------------------------------------
-
-Serial pc(USBTX, USBRX);
-DigitalOut myled(LED1);
-
-int arrivedcount = 0;
-
-void messageArrived(MQTTSN::MessageData& md)
-{
- MQTTSN::Message &message = md.message;
- printf("Message arrived: qos %d, retained %d, dup %d, packetid %d\n, Number: %d", message.qos, message.retained, message.dup, message.id, arrivedcount);
- printf("Payload %.*s\n", message.payloadlen, (char*)message.payload);
- ++arrivedcount;
- puts((char*)message.payload);
-}
-
-int main() {
-
- float version = 0.47;
- char* topic = "mbed-sample";
-
- MQTTSNUDP ipstack = MQTTSNUDP();
-
- char * ssid = "KICS-IOT-DHCP";
- char * seckey = "AAAFFFBBBC";
-
- printf("\r\nX-NUCLEO-IDW01M1 mbed Application\r\n");
- printf("\r\nconnecting to AP\r\n");
-
- if(spwf.connect(ssid, seckey, NSAPI_SECURITY_WPA2)) {
- printf("\r\nnow connected\r\n");
- } else {
- printf("\r\nerror connecting to AP.\r\n");
- return -1;
- }
- const char* Local_IP = spwf.get_ip_address();
- printf("IP Address of Device is: %s\n", Local_IP);
-
- const char* Local_MAC = spwf.get_mac_address();
- printf("MAC Address of Device is: %s\n", Local_MAC);
-
- MQTTSN::Client<MQTTSNUDP, Countdown> client = MQTTSN::Client<MQTTSNUDP, Countdown>(ipstack);
- char* hostname = "192.168.0.114";
- int port = 10000;
- printf("Connecting to %s:%d\n", hostname, port);
- int rc = ipstack.connect(hostname, port);
- if (rc != 0)
- printf("rc from UDP connect is %d\n", rc);
- else
- printf("UDP connected\n");
-
- MQTTSNPacket_connectData data = MQTTSNPacket_connectData_initializer;
- data.clientID.cstring = "mbed-sample";
- data.duration = 60;
- if ((rc = client.connect(data)) != 0)
- printf("rc from MQTT connect is %d\n", rc);
- else
- printf("MQTT Connected\n");
-
- MQTTSN_topicid topicid;
- topicid.type = MQTTSN_TOPIC_TYPE_NORMAL;
- topicid.data.long_.name = topic;
- topicid.data.long_.len = strlen(topic);
- MQTTSN::QoS grantedQoS;
- if ((rc = client.subscribe(topicid, MQTTSN::QOS1, grantedQoS, messageArrived)) != 0)
- printf("rc from MQTT subscribe is %d\n", rc);
- else
- printf("Subscribed to Topic %s\n", topic);
-
- MQTTSN::Message message;
-
- char buf[100];
- int i;
- // QoS 0
- for(i = 0 ; i<= 10; i++){
- sprintf(buf, "Hello World! QoS 0 message from app version %f\n", version);
- message.qos = MQTTSN::QOS0;
- message.retained = false;
- message.dup = false;
- message.payload = (void*)buf;
- message.payloadlen = strlen(buf)+1;
-
- if ((rc = client.publish(topicid, message)) != 0)
- printf("rc from MQTT Publish is %d\n", rc);
- else
- printf("Published Buffer %s to Topic %s\n",buf, topic);
- printf("arrivedcount %d, i = %d\n",arrivedcount, i);
- //while (arrivedcount < i)
- client.yield(100);
- }
- wait(1);
- // QoS 1
-
- sprintf(buf, "Hello World! QoS 1 message from app version %f\n", version);
- message.qos = MQTTSN::QOS1;
- message.payloadlen = strlen(buf)+1;
- if ((rc = client.publish(topicid, message)) != 0)
- printf("rc from MQTT Publish is %d\n", rc);
- else
- printf("Published Buffer %s to Topic %s\n",buf, topic);
- i++;
- //while (arrivedcount < i)
- client.yield(100);
- wait(1);
- // QoS 1
-
- sprintf(buf, "Hello World! QoS 2 message from app version %f\n", version);
- message.qos = MQTTSN::QOS2;
- message.payloadlen = strlen(buf)+1;
- if ((rc = client.publish(topicid, message)) != 0)
- printf("rc from MQTT Publish is %d\n", rc);
- else
- printf("Published Buffer %s to Topic %s\n",buf, topic);
- i++;
- //while (arrivedcount < i)
- client.yield(100);
- wait(1);
- /*
- // QoS 2
- sprintf(buf, "Hello World! QoS 2 message from app version %f\n", version);
- message.qos = MQTTSN::QOS2;
- message.payloadlen = strlen(buf)+1;
- if ((rc = client.publish(topicid, message)) != 0)
- printf("rc from MQTT Publish is %d\n", rc);
- else
- printf("Published Buffer %s to Topic %s\n",buf, topic);
- i++;
- printf("arrivedcount %d, i = %d\n",arrivedcount, i);
- //while (arrivedcount < i)
- client.yield(100);
- wait(3); */
- /*
- // n * QoS 2
- for (int a = 1; a <= 10; a++)
- {
- sprintf(buf, "Hello World! QoS 2 message number %d from app version %f\n", i, version);
- message.qos = MQTTSN::QOS2;
- message.payloadlen = strlen(buf)+1;
- if ((rc = client.publish(topicid, message)) != 0)
- printf("rc from MQTT Publish is %d\n", rc);
- else
- printf("Published Buffer %s to Topic %s\n",buf, topic);
- i++;
- printf("arrivedcount %d, i = %d\n",arrivedcount, i);
- while (arrivedcount < i)
- client.yield(100);
- }
- */
- if ((rc = client.unsubscribe(topicid)) != 0)
- printf("rc from unsubscribe was %d\n", rc);
-
- if ((rc = client.disconnect()) != 0)
- printf("rc from disconnect was %d\n", rc);
-
- ipstack.disconnect();
-
- printf("Version %.2f: finish %d msgs\n", version, arrivedcount);
- printf("Finishing with %d messages received\n", arrivedcount);
-
- return 0;
-
-}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Enumeration.h Mon Mar 11 07:51:06 2019 +0000
@@ -0,0 +1,298 @@
+#include <string>
+
+int ty, op, cst, rsc;
+std::string resourceType, cseType, operation, content, response;
+bool RequestReachability;
+std::string From, csi, api, poa, to, rqi, aei, rn;
+
+bool CreateAE;
+
+void resource_type();
+void Operation_Type();
+void CSE_Type();
+
+void resource_type()
+{
+ switch (ty)
+ {
+ case 1:
+ resourceType = "accessControlPolicy";
+ content = "m2m:acp";
+ break;
+ case 2:
+ resourceType = "AE";
+ content = "m2m:ae";
+ break;
+ case 3:
+ resourceType = "container";
+ content = "m2m:cnt";
+ break;
+ case 4:
+ resourceType = "contentInstance";
+ content = "m2m:cin";
+ break;
+ case 5:
+ resourceType = "CSEBase";
+ content = "m2m:cb";
+ break;
+ case 6:
+ resourceType = "delivery";
+ content = "m2m:dlv";
+ break;
+ case 7:
+ resourceType = "eventConfig";
+ content = "m2m:evcg";
+ break;
+ case 8:
+ resourceType = "execInstance";
+ content = "m2m:exin";
+ break;
+ case 9:
+ resourceType = "group";
+ content = "m2m:grp";
+ break;
+ case 10:
+ resourceType = "locationPolicy";
+ content = "m2m:lcp";
+ break;
+ case 11:
+ resourceType = "m2mServiceSubscriptionProfile";
+ content = "m2m:mssp";
+ break;
+ case 12:
+ resourceType = "mgmtCmd";
+ content = "m2m:mgc";
+ break;
+ case 13:
+ resourceType = "mgmtObj";
+ //content = "m2m:cnt";
+ break;
+ case 14:
+ resourceType = "node";
+ content = "m2m:nod";
+ break;
+ case 15:
+ resourceType = "pollingChannel";
+ content = "m2m:contenth";
+ break;
+ case 16:
+ resourceType = "remoteCSE";
+ content = "m2m:csr";
+ break;
+ case 17:
+ resourceType = "request";
+ content = "m2m:req";
+ break;
+ case 18:
+ resourceType = "schedule";
+ content = "m2m:sch";
+ break;
+ case 19:
+ resourceType = "serviceSubscribedAppRule";
+ content = "m2m:asar";
+ break;
+ case 20:
+ resourceType = "serviceSubscribedNode";
+ content = "m2m:svsn";
+ break;
+ case 21:
+ resourceType = "statsCollect";
+ content = "m2m:stcl";
+ break;
+ case 22:
+ resourceType = "statsConfig";
+ content = "m2m:stcg";
+ break;
+ case 23:
+ resourceType = "subscription";
+ content = "m2m:sub";
+ break;
+ case 10001:
+ resourceType = "accessControlPolicyAnnc";
+ content = "m2m:acpA";
+ break;
+ case 10002:
+ resourceType = "AEAnnc";
+ content = "m2m:aeA";
+ break;
+ case 10003:
+ resourceType = "containerAnnc";
+ content = "m2m:cntA";
+ break;
+ case 10004:
+ resourceType = "contentInstanceAnnc";
+ content = "m2m:cinA";
+ break;
+ case 10009:
+ resourceType = "groupAnnc";
+ content = "m2m:grpA";
+ break;
+ case 10010:
+ resourceType = "locationPolicyAnnc";
+ content = "m2m:lcpA";
+ break;
+ case 10013:
+ resourceType = "mgmtObjAnnc";
+ //content = "m2m:cnt";
+ break;
+ case 10014:
+ resourceType = "nodeAnnc";
+ content = "m2m:nodA";
+ break;
+ case 10016:
+ resourceType = "remoteCSEAnnc";
+ content = "m2m:csrA";
+ break;
+ case 10018:
+ resourceType = "scheduleAnnc";
+ content = "m2m:schA";
+ break;
+ }
+}
+void CSE_Type()
+{
+ switch (cst)
+ {
+ case 1:
+ cseType = "IN_CSE";
+ break;
+ case 2:
+ cseType = "MN_CSE";
+ break;
+ case 3:
+ cseType = "ASN_CSE";
+ break;
+ }
+}
+void Operation_Type() //CRUD+N
+{
+ switch (op)
+ {
+ case 1:
+ operation = "Create";
+ break;
+ case 2:
+ operation = "Retrieve";
+ break;
+ case 3:
+ operation = "Update";
+ break;
+ case 4:
+ operation = "Delete";
+ break;
+ case 5:
+ operation = "Notify";
+ break;
+ }
+}
+void Response_Type()
+{
+ switch (rsc)
+ {
+ //Informational response class
+ case 1000:
+ response = "ACCEPTED";
+ break;
+ case 1001:
+ response = "ACCEPTED for nonBlockingRequestSynch";
+ break;
+ case 1002:
+ response = "ACCEPTED for nonBlockingRequestAsynch";
+ break;
+ //specifies the RSCs for successful responses.
+ case 2000:
+ response = "OK";
+ break;
+ case 2001:
+ response = "CREATED";
+ break;
+ case 2002:
+ response = "DELETED";
+ break;
+ case 2004:
+ response = "UPDATED";
+ break;
+ //RSCs for Originator error response class
+ case 4000:
+ response = "BAD_REQUEST";
+ break;
+ case 4001:
+ response = "RELEASE_VERSION_NOT_SUPPORTED";
+ break;
+ case 4004:
+ response = "NOT_FOUND";
+ break;
+ case 4005:
+ response = "OPERATION_NOT_ALLOWED";
+ break;
+ case 4008:
+ response = "REQUEST_TIMEOUT";
+ break;
+ case 4101:
+ response = "SUBSCRIPTION_CREATOR_HAS_NO_PRIVILEGE";
+ break;
+ case 4102:
+ response = "CONTENTS_UNACCEPTABLE";
+ break;
+ case 4103:
+ response = "ORIGINATOR_HAS_NO_PRIVILEGE";
+ break;
+ case 4104:
+ response = "GROUP_REQUEST_IDENTIFIER_EXISTS";
+ break;
+ case 4105:
+ response = "CONFLICT";
+ break;
+ case 4106:
+ response = "ORIGINATOR_HAS_NOT_REGISTERED";
+ break;
+ case 4107:
+ response = "SECURITY_ASSOCIATION_REQUIRED";
+ break;
+ case 4108:
+ response = "INVALID_CHILD_RESOURCE_TYPE";
+ break;
+ case 4109:
+ response = "NO_MEMBERS";
+ break;
+ case 4110:
+ response = "GROUP_MEMBER_TYPE_INCONSISTENT";
+ break;
+ case 4111:
+ response = "ESPRIM_UNSUPPORTED_OPTION";
+ break;
+ case 4112:
+ response = "ESPRIM_UNKNOWN_KEY_ID";
+ break;
+ case 4113:
+ response = "ESPRIM_UNKNOWN_ORIG_RAND_ID";
+ break;
+ case 4114:
+ response = "ESPRIM_UNKNOWN_RECV_RAND_ID";
+ break;
+ case 4115:
+ response = "ESPRIM_BAD_MAC";
+ break;
+ case 4116:
+ response = "ESPRIM_IMPERSONATION_ERROR";
+ break;
+ case 4117:
+ response = "ORIGINATOR_HAS_ALREADY_REGISTERED";
+ break;
+ case 4118:
+ response = "ONTOLOGY_NOT_AVAILABLE";
+ break;
+ case 4119:
+ response = "LINKED_SEMANTICS_NOT_AVAILABLE";
+ break;
+ case 4120:
+ response = "INVALID_SEMANTICS";
+ break;
+ case 4121:
+ response = "MASHUP_MEMBER_NOT_FOUND";
+ break;
+ case 4122:
+ response = "INVALID_TRIGGER_PURPOSE";
+ break;
+ }
+}
\ No newline at end of file
--- a/MQTTSN.lib Mon Dec 10 08:06:33 2018 +0000 +++ b/MQTTSN.lib Mon Mar 11 07:51:06 2019 +0000 @@ -1,1 +1,1 @@ -https://os.mbed.com/teams/OneM2M/code/MQTTSN/#489a49ad708a +https://os.mbed.com/teams/OneM2M/code/MQTTSN/#1f3743935e44
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/MQTTSN_func.h Mon Mar 11 07:51:06 2019 +0000
@@ -0,0 +1,100 @@
+int connack_rc = 0;
+int retryAttempt = 0;
+int connectTimeout = 1000;
+int rc = 0;
+
+enum connack_return_codes
+{
+ MQTTSN_CONNECTION_ACCEPTED = 0,
+ MQTTSN_REJECTED_CONGESTION = 1,
+ MQTTSN_REJECTED_INVALID_TOPIC_ID = 2,
+ MQTTSN_REJECTED_NOT_SUPPORTED= 3,
+};
+
+static volatile bool isMessageArrived = false;
+int arrivedcount = 0;
+
+int connect(MQTTSN::Client<MQTTSNUDP, Countdown> *client, MQTTSNUDP* ipstack)
+{
+ int rc;
+ MQTTSNPacket_connectData data = MQTTSNPacket_connectData_initializer;
+ data.clientID.cstring = MQTT_CLIENT_ID;
+ data.duration = 60;
+ if ((rc = client->connect(data)) == 0) {
+ printf ("--->MQTT-SN Connected\n\r");
+ }
+ else {
+ printf("MQTT-SN connect returned %d\n", rc);
+ }
+ if (rc >= 0)
+ connack_rc = rc;
+ return rc;
+}
+
+int getConnTimeout(int attemptNumber)
+{ // First 10 attempts try within 3 seconds, next 10 attempts retry after every 1 minute
+ // after 20 attempts, retry every 10 minutes
+ return (attemptNumber < 10) ? 3 : (attemptNumber < 20) ? 60 : 600;
+}
+
+void attemptConnect(MQTTSN::Client<MQTTSNUDP, Countdown> *client, MQTTSNUDP* ipstack)
+{
+ while (connect(client, ipstack) != MQTTSN_CONNECTION_ACCEPTED)
+ {
+ int timeout = getConnTimeout(++retryAttempt);
+ printf("Retry attempt number %d waiting %d\n", retryAttempt, timeout);
+
+ // if ipstack and client were on the heap we could deconstruct and goto a label where they are constructed
+ // or maybe just add the proper members to do this disconnect and call attemptConnect(...)
+ // this works - reset the system when the retry count gets to a threshold
+ if (retryAttempt == 5)
+ NVIC_SystemReset();
+ else
+ wait(timeout);
+ }
+}
+
+void messageArrived(MQTTSN::MessageData& md)
+{
+ MQTTSN::Message &message = md.message;
+ printf("Message arrived: qos %d, retained %d, dup %d, packetid %d\n, Number: %d", message.qos, message.retained, message.dup, message.id, arrivedcount);
+ memcpy(messageBuffer, (char*)message.payload, message.payloadlen);
+ messageBuffer[message.payloadlen] = '\0';
+ printf("Payload %.*s\n", message.payloadlen, (char*)message.payload);
+ printf("Payload length %d\n",message.payloadlen);
+ ++arrivedcount;
+ process_msg();
+ isMessageArrived = true;
+}
+
+int subscribe(MQTTSN::Client<MQTTSNUDP, Countdown> *client, MQTTSNUDP* ipstack, MQTTSN_topicid& topicid)
+{
+ //MQTTSN_topicid topicid;
+ topicid.type = MQTTSN_TOPIC_TYPE_NORMAL;
+ topicid.data.long_.name = MQTT_TOPIC;
+ topicid.data.long_.len = strlen(MQTT_TOPIC);
+ MQTTSN::QoS grantedQoS;
+ return client->subscribe(topicid, MQTTSN::QOS1, grantedQoS, messageArrived);
+}
+
+int publish(MQTTSN::Client<MQTTSNUDP, Countdown> *client, MQTTSNUDP* ipstack, MQTTSN_topicid& topicid2)
+{
+ int rc;
+ if(PUB_REG == false)
+ {
+ if ((rc = subscribe(client, ipstack, topicid2)) != 0)
+ printf("rc from MQTT subscribe is %d\n", rc);
+ else{
+ printf("Subscribed to Topic %s\n", MQTT_TOPIC);
+ PUB_REG = true;
+ }
+ }
+
+ MQTTSN::Message message;
+ message.qos = MQTTSN::QOS1;
+ message.retained = false;
+ message.dup = false;
+ message.payload = (void*)buf;
+ message.payloadlen = strlen(buf)+1;
+ return client->publish(topicid2, message);
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MQTT_server_setting.h Mon Mar 11 07:51:06 2019 +0000 @@ -0,0 +1,30 @@ +#ifndef __MQTT_SERVER_SETTING_H__ +#define __MQTT_SERVER_SETTING_H__ + +#define MQTT_MAX_PAYLOAD_SIZE 700 +#define MQTT_CLIENT_ID "Sensor02" + +//char *buf; +const char * ssid = "KICS-IOT-DHCP"; +const char * seckey = "AAAFFFBBBC"; +bool PUB_REG = false; +/* Buffer size for a receiving message. */ +const int MESSAGE_BUFFER_SIZE = 512; +/* Buffer for a receiving message. */ +char messageBuffer[MESSAGE_BUFFER_SIZE]; + +const char *buffer = NULL; + +char buf[MESSAGE_BUFFER_SIZE]; + +char *MQTT_SERVER_HOST_NAME = "192.168.0.114"; +short MQTT_Atmpt = 0; +int PORT = 10000; +//const char MQTT_SERVER_HOST_NAME[] = "iot.eclipse.org"; +//char *MQTT_CLIENT_ID = "Sensor02"; + +char MQTT_TOPIC[40]; +//const unsigned char* kpsa = "123"; +//const unsigned char* kpsaID = "bridge"; + +#endif /* __MQTT_SERVER_SETTING_H__ */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MbedJSONValue.lib Mon Mar 11 07:51:06 2019 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/teams/OneM2M/code/MbedJSONValue_1/#93f9fd1ed417
--- a/NetworkSocketAPI.lib Mon Dec 10 08:06:33 2018 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://mbed.org/teams/NetworkSocketAPI/code/NetworkSocketAPI/#ea3a618e0818
--- a/X_NUCLEO_IDW01M1v2.lib Mon Dec 10 08:06:33 2018 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -https://developer.mbed.org/teams/ST/code/X_NUCLEO_IDW01M1v2/#c8697141ce44
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/easy-connect.lib Mon Mar 11 07:51:06 2019 +0000 @@ -0,0 +1,1 @@ +https://github.com/ARMmbed/easy-connect/#1cd4bd0db5af4bfc0d46cda20c02a2875faca620
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-http.lib Mon Mar 11 07:51:06 2019 +0000 @@ -0,0 +1,1 @@ +https://developer.mbed.org/teams/sandbox/code/mbed-http/#6daf67a96a91
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-os.lib Mon Mar 11 07:51:06 2019 +0000 @@ -0,0 +1,1 @@ +https://github.com/ARMmbed/mbed-os/#c53d51fe9220728bf8ed27afe7afc1ecc3f6f5d7
--- a/mbed.bld Mon Dec 10 08:06:33 2018 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/2e9cc70d1897 \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed_app.json Mon Mar 11 07:51:06 2019 +0000
@@ -0,0 +1,56 @@
+{
+ "macros": [
+ ],
+ "config": {
+ "main-stack-size": {
+ "value": 8192
+ },
+ "network-interface":{
+ "help": "options are ETHERNET,WIFI_IDW0XX1, WIFI_ESP8266, WIFI_ODIN, WIFI_RTW, MESH_LOWPAN_ND, MESH_THREAD, CELLULAR_ONBOARD",
+ "value": "WIFI_IDW0XX1"
+ },
+ "mesh_radio_type": {
+ "help": "options are ATMEL, MCR20",
+ "value": "ATMEL"
+ },
+ "esp8266-tx": {
+ "help": "Pin used as TX (connects to ESP8266 RX)",
+ "value": "D8"
+ },
+ "esp8266-rx": {
+ "help": "Pin used as RX (connects to ESP8266 TX)",
+ "value": "D2"
+ },
+ "wifi-ssid": {
+ "value": "\"KICS-IOT-DHCP\""
+ },
+ "wifi-password": {
+ "value": "\"AAAFFFBBBC\""
+ },
+ "esp8266-debug": {
+ "value": true
+ }
+ },
+ "target_overrides": {
+ "*": {
+ "target.features_add": ["NANOSTACK", "LOWPAN_ROUTER", "COMMON_PAL"],
+ "mbed-mesh-api.6lowpan-nd-channel-page": 0,
+ "mbed-mesh-api.6lowpan-nd-channel": 12,
+ "mbed-trace.enable": 0,
+ "platform.stdio-baud-rate": 9600,
+ "platform.stdio-convert-newlines": false
+ },
+ "HEXIWEAR": {
+ "esp8266-tx": "PTD3",
+ "esp8266-rx": "PTD2"
+ },
+ "NUCLEO_L476RG": {
+ "esp8266-tx": "D8",
+ "esp8266-rx": "D2"
+ },
+ "NUCLEO_F411RE": {
+ "esp8266-tx": "D8",
+ "esp8266-rx": "D2"
+ }
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/network-helper.h Mon Mar 11 07:51:06 2019 +0000
@@ -0,0 +1,34 @@
+#ifndef _MBED_HTTP_EXAMPLE_H_
+#define _MBED_HTTP_EXAMPLE_H_
+
+#include "mbed.h"
+#include "NetworkInterface.h"
+
+/**
+ * Connect to the network using the default networking interface,
+ * you can also swap this out with a driver for a different networking interface
+ * if you use WiFi: see mbed_app.json for the credentials
+ */
+NetworkInterface *connect_to_default_network_interface() {
+ printf("[NWKH] Connecting to network...\n");
+
+ NetworkInterface* network = NetworkInterface::get_default_instance();
+
+ if (!network) {
+ printf("[NWKH] No network interface found, select an interface in 'network-helper.h'\n");
+ return NULL;
+ }
+
+ nsapi_error_t connect_status = network->connect();
+
+ if (connect_status != NSAPI_ERROR_OK) {
+ printf("[NWKH] Failed to connect to network (%d)\n", connect_status);
+ return NULL;
+ }
+
+ printf("[NWKH] Connected to the network\n");
+ printf("[NWKH] IP address: %s\n", network->get_ip_address());
+ return network;
+}
+
+#endif // _MBED_HTTP_EXAMPLE_H_
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/registration.h Mon Mar 11 07:51:06 2019 +0000
@@ -0,0 +1,70 @@
+
+void Registration(MQTTSN::Client<MQTTSNUDP, Countdown> *client, MQTTSNUDP* ipstack)
+{
+ //Create AE
+ //Mendatory resources: Operation, To, From, Request Identifier ,Resource Type, Content
+ //Resource Specific Attributes [M]: App-ID, requestReachability, supportedReleaseVersions
+ // [0]: PointofAccess, ResourceName
+
+ AE_ID = "S"; //Initial registration
+ //struct Mendatory m1;
+ m1.To = CSE_ID;
+ m1.From = AE_ID;
+ m1.Request_Identifier = "createAE1";
+ m1.Resource_Type = 3;
+ m1.Operation = 1;
+
+ //struct CreateAE CAE;
+ CAE.resourceName = MQTT_CLIENT_ID;
+ CAE.requestReachability = true;
+ CAE.App_ID = "A01.com.sensor01";
+ buffer = Create_AE();
+
+ strncpy(buf, buffer, strlen(buffer));
+
+ delete buffer;
+
+ //////////////////////////////////MQTT Subscribe//////////////////////////////////////////
+
+ //Set Topic to /oneM2M/reg_resp/Sensor01/CSE_01
+ char tpc_ty[] = "reg_resp";
+ char orignator[] = MQTT_CLIENT_ID;
+ char receiver[] = "CSE_01";
+ //create_Topic();
+
+ sprintf(MQTT_TOPIC,"/oneM2M/%s/%s/%s",tpc_ty,orignator,receiver);
+ printf("Topic is %s", MQTT_TOPIC);
+
+ MQTTSN_topicid topicid;
+ if ((rc = subscribe(client, ipstack, topicid)) != 0)
+ printf("rc from MQTT subscribe is %d\n", rc);
+ else
+ printf("Subscribed to Topic %s\n", MQTT_TOPIC);
+
+ //Set Topic to /oneM2M/reg_req/Sensor01/CSE_01
+ strcpy(tpc_ty, "reg_req");
+ //create_Topic();
+
+ sprintf(MQTT_TOPIC,"/oneM2M/%s/%s/%s",tpc_ty,orignator,receiver);
+ printf("Topic is %s", MQTT_TOPIC);
+ //PUBLISH
+ MQTTSN_topicid topicid2;
+ if ((rc = publish(client, ipstack, topicid2)) != 0)
+ {
+ printf("rc from MQTT Publish is %d\n", rc);
+ if ((rc = client->unsubscribe(topicid2)) != 0)
+ printf("rc from unsubscribe was %d\n", rc);
+ else{
+ printf("Unsubscribed from Topic %s\n", MQTT_TOPIC);
+ PUB_REG = false;
+ }
+ }
+ else
+ printf("Published Buffer: %s to Topic %s\n",buf, MQTT_TOPIC);
+
+ while(reg_resp == false)
+ {
+ client->yield(4000);
+ }
+ //wait for response
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sensor.h Mon Mar 11 07:51:06 2019 +0000
@@ -0,0 +1,241 @@
+#include <string>
+void process_rsc(MbedJSONValue &MSG);
+
+bool reg_resp = false;
+
+char* CSE_ID = "cse1";
+char* AE_ID;
+
+struct Mendatory
+{
+ string To;
+ string From;
+ string Request_Identifier;
+ int Operation;
+ int Resource_Type;
+}m1;
+
+struct CreateAE
+{
+ string resourceName;
+ string App_ID;
+ string pointOfAccess;
+ bool requestReachability;
+}CAE;
+
+const char* Create_AE()
+{
+ MbedJSONValue MSG, demo, demo2, demo3;
+
+ std::string s;
+
+ //fill the object
+
+ demo3["api"] = CAE.App_ID;
+ demo3["rn"] = CAE.resourceName;
+ demo3["rr"] = CAE.requestReachability;
+ demo2["m2m:ae"] = demo3;
+ demo["fr"] = m1.From;
+ demo["op"] = m1.Operation;
+ demo["pc"] = demo2;
+ demo["rqi"] = m1.Request_Identifier;
+ demo["to"] = m1.To;
+ demo["ty"] = m1.Resource_Type;
+
+ //serialize it into a JSON string
+ s = demo.serialize();
+ printf("\nMSG SIZE: %d\n", s.length());
+ //printf("json: %s\r\n", s.c_str());
+ return s.c_str();
+}
+
+void process_msg()
+{
+ MbedJSONValue MSG;
+ //printf("Before Parsing\n");
+ parse(MSG, messageBuffer);
+ //bool temp; //Check fot parameters presence
+
+ ////////////////////////resource Type Parameter (Mendatory parameter)//////////////////////
+ if(MSG.hasMember("rsc"))
+ {
+ rsc = MSG["rsc"].get<int>();
+ printf("Response Status Code: %d\r\n", rsc);
+ Response_Type();
+ printf("Response Status: %s\r\n", response.c_str());
+ process_rsc(MSG);
+ return;
+ }
+
+ ////////////////////////resource Type Parameter (Mendatory parameter)//////////////////////
+ if(MSG.hasMember("ty"))
+ {
+ ty = MSG["ty"].get<int>();
+ printf("ResourceType: %d\r\n", ty);
+ resource_type();
+ printf("ResourceType: %s\r\n", resourceType.c_str());
+ }
+ else {
+ //add response code for no mendatory parameter
+ return; }
+
+ ////////////////////////From parameter (Mendatory parameter[optional for Create AE])//////////
+ if(MSG.hasMember("fr"))
+ {
+ From = MSG["fr"].get<std::string>();
+ printf("From: %s\r\n", From.c_str());
+ }
+ else {
+ //add Response Status Code for no mendatory parameter BAD_REQUEST
+ return; }
+
+ ////////////////////////Operation Parameter (Mendatory parameter)//////////////////////
+ if(MSG.hasMember("op"))
+ {
+ op = MSG["op"].get<int>();
+ printf("Operation: %d\r\n", op);
+ Operation_Type();
+ printf("Operation: %s\r\n", operation.c_str());
+ }
+ else {
+ //add response code for no mendatory parameter
+ return; }
+
+ ////////////////////////To Parameter (Mendatory parameter)//////////////////////
+ if(MSG.hasMember("to"))
+ {
+ to = MSG["to"].get<std::string>();
+ printf("To: %s\r\n", to.c_str());
+ }
+ else {
+ //add response code for no mendatory parameter
+ return; }
+
+ ////////////////////////Request Identifier (Mendatory parameter)//////////////////////
+ if(MSG.hasMember("rqi"))
+ {
+ rqi = MSG["rqi"].get<std::string>();
+ printf("Request Identifier: %s\r\n", rqi.c_str());
+ }
+ else {
+ //add response code for no mendatory parameter
+ return; }
+
+ ////////////////////////Response Status Code
+ if(MSG.hasMember("rsc"))
+ {
+ rsc = MSG["rsc"].get<int>();
+ printf("Response Status Code: %d\r\n", rsc);
+ Response_Type();
+ printf("Response Status: %s\r\n", response.c_str());
+ }
+ MbedJSONValue &MSG_1 = MSG["pc"][content]; //content value depends on the resource type e.g. m2m:ae for resource type 2
+
+ //////////////////////// Resource specific attributes CSE-ID
+ if(MSG_1.hasMember("csi"))
+ {
+ csi = MSG_1["csi"].get<std::string>();
+ printf("CSI: %s\r\n", csi.c_str());
+ }
+
+ //////////////////////// Resource specific attributes Point of Access
+ if(MSG_1.hasMember("poa"))
+ {
+ poa = MSG_1["poa"].get<std::string>();
+ printf("POA: %s\r\n", poa.c_str());
+ }
+
+ /////////////////////// Resource specific attributes CSE Type
+ if(MSG_1.hasMember("cst"))
+ {
+ cst = MSG_1["cst"].get<int>();
+ printf("CSE Type: %d\r\n", cst);
+ CSE_Type();
+ printf("CSE Type: %s\r\n", cseType.c_str());
+ }
+
+ /////////////////////// Resource specific attributes RequestReachability
+ if(MSG_1.hasMember("rr"))
+ {
+ RequestReachability = MSG_1["rr"].get<bool>();
+ printf("RR: %s\r\n", RequestReachability? "true" : "false");
+ }
+
+ /////////////////////// Resource specific attributes App-ID
+ if(MSG_1.hasMember("api"))
+ {
+ api = MSG_1["api"].get<std::string>();
+ printf("App-ID: %s\r\n", api.c_str());
+ }
+ // msg[0] = '\0';
+ //MSG.~MbedJSONValue();
+ //MSG_1.~MbedJSONValue();*/
+}
+
+void process_rsc(MbedJSONValue &MSG)
+{
+ if(MSG.hasMember("rqi"))
+ {
+ rqi = MSG["rqi"].get<std::string>();
+ printf("Request Identifier: %s\r\n", rqi.c_str());
+ }
+ else {
+ //add response code for no mendatory parameter
+ return; }
+ if(MSG.hasMember("to"))
+ {
+ to = MSG["to"].get<std::string>();
+ printf("To: %s\r\n", to.c_str());
+ }
+ else {
+ //add response code for no mendatory parameter
+ return; }
+ if(MSG.hasMember("fr"))
+ {
+ From = MSG["fr"].get<std::string>();
+ printf("From: %s\r\n", From.c_str());
+ }
+ else {
+ //add response code for no mendatory parameter
+ return; }
+
+ MbedJSONValue &MSG_1 = MSG["pc"][content];
+
+ if(MSG_1.hasMember("ty"))
+ {
+ ty = MSG_1["ty"].get<int>();
+ printf("ResourceType: %d\r\n", ty);
+ resource_type();
+ printf("ResourceType: %s\r\n", resourceType.c_str());
+ }
+ else {
+ //add response code for no mendatory parameter
+ return; }
+
+ if(MSG_1.hasMember("rr"))
+ {
+ RequestReachability = MSG_1["rr"].get<bool>();
+ printf("RR: %s\r\n", RequestReachability? "true" : "false");
+ }
+ if(MSG_1.hasMember("aei"))
+ {
+ aei = MSG_1["aei"].get<std::string>();
+ printf("AE_ID: %s\r\n", aei.c_str());
+ }
+ if(MSG_1.hasMember("poa"))
+ {
+ poa = MSG_1["poa"].get<std::string>();
+ printf("POA: %s\r\n", poa.c_str());
+ }
+ if(MSG_1.hasMember("rn"))
+ {
+ rn = MSG_1["rn"].get<std::string>();
+ printf("Resource Name: %s\r\n", rn.c_str());
+ }
+ if(MSG_1.hasMember("api"))
+ {
+ api = MSG_1["api"].get<std::string>();
+ printf("App-ID: %s\r\n", api.c_str());
+ }
+ return;
+}
\ No newline at end of file