123

Dependencies:   MQTTSN

Committer:
m_ahsan
Date:
Tue Aug 06 05:32:43 2019 +0000
Revision:
15:8c473836feba
123

Who changed what in which revision?

UserRevisionLine numberNew contents of line
m_ahsan 15:8c473836feba 1
m_ahsan 15:8c473836feba 2 int contentInstance(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 R1.To = CSE_ID;
m_ahsan 15:8c473836feba 12 R1.From = aei;
m_ahsan 15:8c473836feba 13 R1.Request_Identifier = "createCin01";
m_ahsan 15:8c473836feba 14 R1.Resource_Type = 4;
m_ahsan 15:8c473836feba 15 R1.Operation = 1;
m_ahsan 15:8c473836feba 16
m_ahsan 15:8c473836feba 17 //struct CreateAE CAE;
m_ahsan 15:8c473836feba 18 CIN.resourceName = "cin_monitor01";
m_ahsan 15:8c473836feba 19 CIN.contentInfo = "text/plains:0";
m_ahsan 15:8c473836feba 20 CIN.content = "25";
m_ahsan 15:8c473836feba 21 //buffer = Create_Cnt();
m_ahsan 15:8c473836feba 22 lcl = false;
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 /*if(isMessageArrived) {
m_ahsan 15:8c473836feba 36 isMessageArrived = false;
m_ahsan 15:8c473836feba 37 // Just print it out here.
m_ahsan 15:8c473836feba 38 //printf("\r\nMessage arrived:\r\n%s\r\n", messageBuffer);
m_ahsan 15:8c473836feba 39 //process_msg();
m_ahsan 15:8c473836feba 40 //free(messageBuffer);
m_ahsan 15:8c473836feba 41 } */
m_ahsan 15:8c473836feba 42 if(rsc != 0){
m_ahsan 15:8c473836feba 43 //reg_resp = true;
m_ahsan 15:8c473836feba 44 printf("rsc = %d\n",rsc);
m_ahsan 15:8c473836feba 45 break;
m_ahsan 15:8c473836feba 46 }
m_ahsan 15:8c473836feba 47 else rsc = 0;
m_ahsan 15:8c473836feba 48 }
m_ahsan 15:8c473836feba 49 if(rsc == 2001 ){
m_ahsan 15:8c473836feba 50 rsc = 0;
m_ahsan 15:8c473836feba 51 return 0;
m_ahsan 15:8c473836feba 52 }
m_ahsan 15:8c473836feba 53 else if(rsc == 2002){
m_ahsan 15:8c473836feba 54 rsc = 0;
m_ahsan 15:8c473836feba 55 return -1;
m_ahsan 15:8c473836feba 56 }
m_ahsan 15:8c473836feba 57 //wait for response
m_ahsan 15:8c473836feba 58 return 0;
m_ahsan 15:8c473836feba 59 }