123
Dependencies: MQTTSN
Subscription.h@15:8c473836feba, 2019-08-06 (annotated)
- Committer:
- m_ahsan
- Date:
- Tue Aug 06 05:32:43 2019 +0000
- Revision:
- 15:8c473836feba
123
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
m_ahsan | 15:8c473836feba | 1 | |
m_ahsan | 15:8c473836feba | 2 | int Subscription(MQTTSN::Client<MQTTSNUDP, Countdown> *client, MQTTSNUDP* ipstack, MQTTSN_topicid& topicid) |
m_ahsan | 15:8c473836feba | 3 | { |
m_ahsan | 15:8c473836feba | 4 | //Create Subscription |
m_ahsan | 15:8c473836feba | 5 | //Mendatory resources: Operation, To, From, Request Identifier ,Resource Type, Content |
m_ahsan | 15:8c473836feba | 6 | //Resource Specific Attributes [M]: |
m_ahsan | 15:8c473836feba | 7 | // [0]: |
m_ahsan | 15:8c473836feba | 8 | |
m_ahsan | 15:8c473836feba | 9 | //struct Mendatory m1; (to, fr, rqi, ty, op) |
m_ahsan | 15:8c473836feba | 10 | Request R1; |
m_ahsan | 15:8c473836feba | 11 | R1.To = CSE_ID; |
m_ahsan | 15:8c473836feba | 12 | R1.From = aei; |
m_ahsan | 15:8c473836feba | 13 | R1.Request_Identifier = "createSub01"; |
m_ahsan | 15:8c473836feba | 14 | R1.Resource_Type = 23; |
m_ahsan | 15:8c473836feba | 15 | R1.Operation = 1; |
m_ahsan | 15:8c473836feba | 16 | |
m_ahsan | 15:8c473836feba | 17 | //struct CreateSub CSub; |
m_ahsan | 15:8c473836feba | 18 | CSub.notificationEventType = 3; |
m_ahsan | 15:8c473836feba | 19 | CSub.resourceName = "sub_monitor01";; |
m_ahsan | 15:8c473836feba | 20 | CSub.notificationURI = aei; |
m_ahsan | 15:8c473836feba | 21 | CSub.notificationContentType = 1; |
m_ahsan | 15:8c473836feba | 22 | lcl = false; |
m_ahsan | 15:8c473836feba | 23 | //buffer = Create_Cnt(); |
m_ahsan | 15:8c473836feba | 24 | buf = Create_Req(R1); |
m_ahsan | 15:8c473836feba | 25 | //buf[0] = '\0'; |
m_ahsan | 15:8c473836feba | 26 | |
m_ahsan | 15:8c473836feba | 27 | //PUBLISH |
m_ahsan | 15:8c473836feba | 28 | if ((rc = publish(client, ipstack, topicid)) != 0) |
m_ahsan | 15:8c473836feba | 29 | printf("rc from MQTT Publish is %d\n", rc); |
m_ahsan | 15:8c473836feba | 30 | else |
m_ahsan | 15:8c473836feba | 31 | printf("Published Buffer: %s to Topic %s\n",buf, MQTT_TOPIC); |
m_ahsan | 15:8c473836feba | 32 | |
m_ahsan | 15:8c473836feba | 33 | while(1) |
m_ahsan | 15:8c473836feba | 34 | { |
m_ahsan | 15:8c473836feba | 35 | client->yield(4000); |
m_ahsan | 15:8c473836feba | 36 | if(rsc != 0){ |
m_ahsan | 15:8c473836feba | 37 | printf("rsc = %d\n",rsc); |
m_ahsan | 15:8c473836feba | 38 | break; |
m_ahsan | 15:8c473836feba | 39 | } |
m_ahsan | 15:8c473836feba | 40 | else rsc = 0; |
m_ahsan | 15:8c473836feba | 41 | } |
m_ahsan | 15:8c473836feba | 42 | if(rsc == 2001 ){ |
m_ahsan | 15:8c473836feba | 43 | rsc = 0; |
m_ahsan | 15:8c473836feba | 44 | return 0; |
m_ahsan | 15:8c473836feba | 45 | } |
m_ahsan | 15:8c473836feba | 46 | else if(rsc == 2002){ |
m_ahsan | 15:8c473836feba | 47 | rsc = 0; |
m_ahsan | 15:8c473836feba | 48 | return -1; |
m_ahsan | 15:8c473836feba | 49 | } |
m_ahsan | 15:8c473836feba | 50 | return 0; |
m_ahsan | 15:8c473836feba | 51 | } |
m_ahsan | 15:8c473836feba | 52 | |
m_ahsan | 15:8c473836feba | 53 | int delete_sub (MQTTSN::Client<MQTTSNUDP, Countdown> *client, MQTTSNUDP* ipstack, MQTTSN_topicid& topicid) |
m_ahsan | 15:8c473836feba | 54 | { |
m_ahsan | 15:8c473836feba | 55 | Request R1; |
m_ahsan | 15:8c473836feba | 56 | //Create to parameter URI cse01/AE01/cont_monitor01 |
m_ahsan | 15:8c473836feba | 57 | sprintf(URI,"/%s/%s/sub_monitor01",CSE_ID, c_aei); |
m_ahsan | 15:8c473836feba | 58 | R1.To = URI; |
m_ahsan | 15:8c473836feba | 59 | R1.From = aei; |
m_ahsan | 15:8c473836feba | 60 | R1.Request_Identifier = "deleteSub01"; |
m_ahsan | 15:8c473836feba | 61 | R1.Operation = 4; |
m_ahsan | 15:8c473836feba | 62 | buf = Delete_Req(R1); |
m_ahsan | 15:8c473836feba | 63 | //PUBLISH |
m_ahsan | 15:8c473836feba | 64 | if ((rc = publish(client, ipstack, topicid)) != 0) |
m_ahsan | 15:8c473836feba | 65 | printf("rc from MQTT Publish is %d\n", rc); |
m_ahsan | 15:8c473836feba | 66 | else |
m_ahsan | 15:8c473836feba | 67 | printf("Published Buffer: %s to Topic %s\n",buf, MQTT_TOPIC); |
m_ahsan | 15:8c473836feba | 68 | while(1) |
m_ahsan | 15:8c473836feba | 69 | { |
m_ahsan | 15:8c473836feba | 70 | client->yield(4000); |
m_ahsan | 15:8c473836feba | 71 | if(rsc != 0){ |
m_ahsan | 15:8c473836feba | 72 | printf("rsc = %d\n",rsc); |
m_ahsan | 15:8c473836feba | 73 | break; |
m_ahsan | 15:8c473836feba | 74 | } |
m_ahsan | 15:8c473836feba | 75 | else rsc = 0; |
m_ahsan | 15:8c473836feba | 76 | } |
m_ahsan | 15:8c473836feba | 77 | return rsc; |
m_ahsan | 15:8c473836feba | 78 | } |