OneM2M / Mbed OS MQTTSN_AE_v1

Dependencies:   MQTTSN mbed-http

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers registration.h Source File

registration.h

00001 
00002 void Registration(MQTTSN::Client<MQTTSNUDP, Countdown> *client, MQTTSNUDP* ipstack)
00003 {
00004     //Create AE
00005     //Mendatory resources: Operation, To, From, Request Identifier ,Resource Type, Content 
00006     //Resource Specific Attributes [M]: App-ID, requestReachability, supportedReleaseVersions
00007     //                              [0]: PointofAccess, ResourceName
00008     
00009     AE_ID = "S";                    //Initial registration
00010     //struct Mendatory m1;
00011     m1.To = CSE_ID; 
00012     m1.From = AE_ID;
00013     m1.Request_Identifier = "createAE1";
00014     m1.Resource_Type = 3;
00015     m1.Operation = 1;
00016     
00017     //struct CreateAE CAE;
00018     CAE.resourceName = MQTT_CLIENT_ID;
00019     CAE.requestReachability = true;
00020     CAE.App_ID = "A01.com.sensor01";
00021     buffer = Create_AE();
00022 
00023     strncpy(buf, buffer, strlen(buffer));
00024 
00025     delete buffer;
00026     
00027     //////////////////////////////////MQTT Subscribe//////////////////////////////////////////
00028     
00029     //Set Topic to /oneM2M/reg_resp/Sensor01/CSE_01
00030     char tpc_ty[] = "reg_resp";
00031     char orignator[] = MQTT_CLIENT_ID; 
00032     char receiver[] = "CSE_01";
00033     //create_Topic();
00034     
00035     sprintf(MQTT_TOPIC,"/oneM2M/%s/%s/%s",tpc_ty,orignator,receiver);
00036     printf("Topic is %s", MQTT_TOPIC);
00037     
00038     MQTTSN_topicid topicid;
00039     if ((rc = subscribe(client, ipstack, topicid)) != 0)
00040          printf("rc from MQTT subscribe is %d\n", rc);
00041     else
00042          printf("Subscribed to Topic %s\n", MQTT_TOPIC);
00043 
00044     //Set Topic to /oneM2M/reg_req/Sensor01/CSE_01
00045     strcpy(tpc_ty, "reg_req");
00046     //create_Topic();
00047     
00048     sprintf(MQTT_TOPIC,"/oneM2M/%s/%s/%s",tpc_ty,orignator,receiver);
00049     printf("Topic is %s", MQTT_TOPIC);
00050     //PUBLISH
00051     MQTTSN_topicid topicid2;
00052     if ((rc = publish(client, ipstack, topicid2)) != 0)
00053     {
00054          printf("rc from MQTT Publish is %d\n", rc);
00055          if ((rc = client->unsubscribe(topicid2)) != 0)
00056          printf("rc from unsubscribe was %d\n", rc);
00057          else{
00058              printf("Unsubscribed from Topic %s\n", MQTT_TOPIC);
00059              PUB_REG = false;
00060          } 
00061     }
00062     else
00063          printf("Published Buffer: %s to Topic %s\n",buf, MQTT_TOPIC);
00064     
00065     while(reg_resp == false)
00066     {     
00067         client->yield(4000);
00068     }    
00069     //wait for response
00070 }