123
Dependencies: MQTTSN
container.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 Container(MQTTSN::Client<MQTTSNUDP, Countdown> *client, MQTTSNUDP* ipstack, MQTTSN_topicid& topicid) |
m_ahsan | 15:8c473836feba | 3 | { |
m_ahsan | 15:8c473836feba | 4 | //Create Container |
m_ahsan | 15:8c473836feba | 5 | //Mendatory resources: Operation, To, From, Request Identifier ,Resource Type, Content |
m_ahsan | 15:8c473836feba | 6 | //Resource Specific Attributes [M]: App-ID, requestReachability, supportedReleaseVersions |
m_ahsan | 15:8c473836feba | 7 | // [0]: PointofAccess, ResourceName |
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 | //Create to parameter URI cse01/AE01 |
m_ahsan | 15:8c473836feba | 12 | sprintf(URI,"/%s/%s",CSE_ID, c_aei); |
m_ahsan | 15:8c473836feba | 13 | R1.To = URI; |
m_ahsan | 15:8c473836feba | 14 | R1.From = aei; |
m_ahsan | 15:8c473836feba | 15 | R1.Request_Identifier = "createCont01"; |
m_ahsan | 15:8c473836feba | 16 | R1.Resource_Type = 3; |
m_ahsan | 15:8c473836feba | 17 | R1.Operation = 1; |
m_ahsan | 15:8c473836feba | 18 | |
m_ahsan | 15:8c473836feba | 19 | //struct CreateAE CAE; |
m_ahsan | 15:8c473836feba | 20 | CAE.resourceName = "cont_monitor01"; |
m_ahsan | 15:8c473836feba | 21 | lcl = false; |
m_ahsan | 15:8c473836feba | 22 | //buffer = Create_Cnt(); |
m_ahsan | 15:8c473836feba | 23 | buf = Create_Req(R1); |
m_ahsan | 15:8c473836feba | 24 | //buf[0] = '\0'; |
m_ahsan | 15:8c473836feba | 25 | |
m_ahsan | 15:8c473836feba | 26 | //PUBLISH |
m_ahsan | 15:8c473836feba | 27 | if ((rc = publish(client, ipstack, topicid)) != 0) |
m_ahsan | 15:8c473836feba | 28 | printf("rc from MQTT Publish is %d\n", rc); |
m_ahsan | 15:8c473836feba | 29 | else |
m_ahsan | 15:8c473836feba | 30 | printf("Published Buffer: %s to Topic %s\n",buf, MQTT_TOPIC); |
m_ahsan | 15:8c473836feba | 31 | |
m_ahsan | 15:8c473836feba | 32 | while(1) |
m_ahsan | 15:8c473836feba | 33 | { |
m_ahsan | 15:8c473836feba | 34 | client->yield(4000); |
m_ahsan | 15:8c473836feba | 35 | |
m_ahsan | 15:8c473836feba | 36 | if(rsc != 0){ |
m_ahsan | 15:8c473836feba | 37 | //reg_resp = true; |
m_ahsan | 15:8c473836feba | 38 | printf("rsc = %d\n",rsc); |
m_ahsan | 15:8c473836feba | 39 | break; |
m_ahsan | 15:8c473836feba | 40 | } |
m_ahsan | 15:8c473836feba | 41 | else rsc = 0; |
m_ahsan | 15:8c473836feba | 42 | } |
m_ahsan | 15:8c473836feba | 43 | if(rsc == 2001 ){ |
m_ahsan | 15:8c473836feba | 44 | rsc = 0; |
m_ahsan | 15:8c473836feba | 45 | return 0; |
m_ahsan | 15:8c473836feba | 46 | } |
m_ahsan | 15:8c473836feba | 47 | else if(rsc == 2002){ |
m_ahsan | 15:8c473836feba | 48 | rsc = 0; |
m_ahsan | 15:8c473836feba | 49 | return -1; |
m_ahsan | 15:8c473836feba | 50 | } |
m_ahsan | 15:8c473836feba | 51 | return 0; |
m_ahsan | 15:8c473836feba | 52 | } |
m_ahsan | 15:8c473836feba | 53 | |
m_ahsan | 15:8c473836feba | 54 | int delete_cnt (MQTTSN::Client<MQTTSNUDP, Countdown> *client, MQTTSNUDP* ipstack, MQTTSN_topicid& topicid) |
m_ahsan | 15:8c473836feba | 55 | { |
m_ahsan | 15:8c473836feba | 56 | Request R1; |
m_ahsan | 15:8c473836feba | 57 | //Create to parameter URI cse01/AE01/cont_monitor01 |
m_ahsan | 15:8c473836feba | 58 | sprintf(URI,"/%s/%s/cont_monitor01",CSE_ID, c_aei); |
m_ahsan | 15:8c473836feba | 59 | R1.To = URI; |
m_ahsan | 15:8c473836feba | 60 | R1.From = aei; |
m_ahsan | 15:8c473836feba | 61 | R1.Request_Identifier = "deleteCont01"; |
m_ahsan | 15:8c473836feba | 62 | R1.Operation = 4; |
m_ahsan | 15:8c473836feba | 63 | buf = Delete_Req(R1); |
m_ahsan | 15:8c473836feba | 64 | //PUBLISH |
m_ahsan | 15:8c473836feba | 65 | if ((rc = publish(client, ipstack, topicid)) != 0) |
m_ahsan | 15:8c473836feba | 66 | printf("rc from MQTT Publish is %d\n", rc); |
m_ahsan | 15:8c473836feba | 67 | else |
m_ahsan | 15:8c473836feba | 68 | printf("Published Buffer: %s to Topic %s\n",buf, MQTT_TOPIC); |
m_ahsan | 15:8c473836feba | 69 | while(1) |
m_ahsan | 15:8c473836feba | 70 | { |
m_ahsan | 15:8c473836feba | 71 | client->yield(4000); |
m_ahsan | 15:8c473836feba | 72 | if(rsc != 0){ |
m_ahsan | 15:8c473836feba | 73 | printf("rsc = %d\n",rsc); |
m_ahsan | 15:8c473836feba | 74 | break; |
m_ahsan | 15:8c473836feba | 75 | } |
m_ahsan | 15:8c473836feba | 76 | else rsc = 0; |
m_ahsan | 15:8c473836feba | 77 | } |
m_ahsan | 15:8c473836feba | 78 | return rsc; |
m_ahsan | 15:8c473836feba | 79 | } |