v1

Dependencies:   MQTTSN mbed-http

Revision:
15:557d0008dd2d
--- /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