OneM2M / Mbed OS MQTTSN_AE_ESP_copy-1

Dependencies:   MQTTSN

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Subscription.h Source File

Subscription.h

00001 
00002 int Subscription(MQTTSN::Client<MQTTSNUDP, Countdown> *client, MQTTSNUDP* ipstack,  MQTTSN_topicid& topicid)
00003 {
00004     //Create Subscription
00005     //Mendatory resources: Operation, To, From, Request Identifier ,Resource Type, Content 
00006     //Resource Specific Attributes [M]: 
00007     //                              [0]: 
00008 
00009     //struct Mendatory m1; (to, fr, rqi, ty, op)
00010     Request R1;
00011     R1.To = CSE_ID; 
00012     R1.From = aei;
00013     R1.Request_Identifier = "createSub01";
00014     R1.Resource_Type = 23;
00015     R1.Operation = 1;
00016     
00017     //struct CreateSub CSub;
00018     CSub.notificationEventType = 3;
00019     CSub.resourceName = "sub_monitor01";;
00020     CSub.notificationURI = aei; 
00021     CSub.notificationContentType = 1;
00022     lcl = false;
00023     //buffer = Create_Cnt();
00024     buf = Create_Req(R1);
00025     //buf[0] = '\0'; 
00026         
00027     //PUBLISH
00028     if ((rc = publish(client, ipstack, topicid)) != 0)
00029          printf("rc from MQTT Publish is %d\n", rc);
00030     else
00031          printf("Published Buffer: %s to Topic %s\n",buf, MQTT_TOPIC);
00032 
00033     while(1)
00034     {  
00035         client->yield(4000);
00036         if(rsc != 0){ 
00037             printf("rsc = %d\n",rsc);
00038             break;
00039         }
00040         else rsc = 0;
00041     }
00042     if(rsc == 2001 ){ 
00043         rsc = 0;
00044         return 0;
00045     }
00046     else if(rsc == 2002){
00047         rsc = 0;
00048         return -1;
00049     }
00050     return 0;
00051 }
00052 
00053 int delete_sub (MQTTSN::Client<MQTTSNUDP, Countdown> *client, MQTTSNUDP* ipstack,  MQTTSN_topicid& topicid)
00054 {
00055     Request R1;
00056     //Create to parameter URI cse01/AE01/cont_monitor01
00057     sprintf(URI,"/%s/%s/sub_monitor01",CSE_ID, c_aei);
00058     R1.To = URI; 
00059     R1.From = aei;
00060     R1.Request_Identifier = "deleteSub01";
00061     R1.Operation = 4;
00062     buf = Delete_Req(R1);
00063     //PUBLISH
00064     if ((rc = publish(client, ipstack, topicid)) != 0)
00065          printf("rc from MQTT Publish is %d\n", rc);
00066     else
00067          printf("Published Buffer: %s to Topic %s\n",buf, MQTT_TOPIC);
00068     while(1)
00069     {
00070         client->yield(4000);
00071         if(rsc != 0){ 
00072             printf("rsc = %d\n",rsc);
00073             break;
00074         }
00075         else rsc = 0;
00076     }
00077     return rsc;
00078 }