123
Dependencies: MQTTSN
registration.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 Registration(MQTTSN::Client<MQTTSNUDP, Countdown> *client, MQTTSNUDP* ipstack, MQTTSN_topicid& topicid) |
m_ahsan | 15:8c473836feba | 3 | { |
m_ahsan | 15:8c473836feba | 4 | //Create AE |
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 | Request R1; |
m_ahsan | 15:8c473836feba | 9 | AE_ID = "S"; //Initial registration |
m_ahsan | 15:8c473836feba | 10 | //struct Mendatory m1; |
m_ahsan | 15:8c473836feba | 11 | R1.To = CSE_ID; |
m_ahsan | 15:8c473836feba | 12 | R1.From = AE_ID; |
m_ahsan | 15:8c473836feba | 13 | R1.Request_Identifier = "createAE11"; |
m_ahsan | 15:8c473836feba | 14 | R1.Resource_Type = 2; |
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 | CAE.resourceName = MQTT_CLIENT_ID; |
m_ahsan | 15:8c473836feba | 19 | CAE.requestReachability = true; |
m_ahsan | 15:8c473836feba | 20 | CAE.App_ID = "A01.com.sensor011"; |
m_ahsan | 15:8c473836feba | 21 | //buffer = Create_AE(); |
m_ahsan | 15:8c473836feba | 22 | lcl = false; |
m_ahsan | 15:8c473836feba | 23 | buf = Create_Req(R1); |
m_ahsan | 15:8c473836feba | 24 | printf("string in buf is %s\n",buf); |
m_ahsan | 15:8c473836feba | 25 | //buf[0] = '\0'; |
m_ahsan | 15:8c473836feba | 26 | |
m_ahsan | 15:8c473836feba | 27 | |
m_ahsan | 15:8c473836feba | 28 | //PUBLISH |
m_ahsan | 15:8c473836feba | 29 | |
m_ahsan | 15:8c473836feba | 30 | if ((rc = publish(client, ipstack, topicid)) != 0) |
m_ahsan | 15:8c473836feba | 31 | printf("rc from MQTT Publish is %d\n", rc); |
m_ahsan | 15:8c473836feba | 32 | else |
m_ahsan | 15:8c473836feba | 33 | printf("Published Buffer: %s to Topic %s\n",buf, MQTT_TOPIC); |
m_ahsan | 15:8c473836feba | 34 | |
m_ahsan | 15:8c473836feba | 35 | while(1) |
m_ahsan | 15:8c473836feba | 36 | { |
m_ahsan | 15:8c473836feba | 37 | |
m_ahsan | 15:8c473836feba | 38 | client->yield(4000); |
m_ahsan | 15:8c473836feba | 39 | /*if(isMessageArrived) { |
m_ahsan | 15:8c473836feba | 40 | isMessageArrived = false; |
m_ahsan | 15:8c473836feba | 41 | // Just print it out here. |
m_ahsan | 15:8c473836feba | 42 | //printf("\r\nMessage arrived:\r\n%s\r\n", messageBuffer); |
m_ahsan | 15:8c473836feba | 43 | //process_msg(); |
m_ahsan | 15:8c473836feba | 44 | |
m_ahsan | 15:8c473836feba | 45 | //free(messageBuffer); |
m_ahsan | 15:8c473836feba | 46 | } */ |
m_ahsan | 15:8c473836feba | 47 | if(rsc != 0){ |
m_ahsan | 15:8c473836feba | 48 | //reg_resp = true; |
m_ahsan | 15:8c473836feba | 49 | printf("rsc = %d\n",rsc); |
m_ahsan | 15:8c473836feba | 50 | break; |
m_ahsan | 15:8c473836feba | 51 | } |
m_ahsan | 15:8c473836feba | 52 | else rsc = 0; |
m_ahsan | 15:8c473836feba | 53 | } |
m_ahsan | 15:8c473836feba | 54 | if(rsc == 2001 ){ |
m_ahsan | 15:8c473836feba | 55 | rsc = 0; |
m_ahsan | 15:8c473836feba | 56 | return 0; |
m_ahsan | 15:8c473836feba | 57 | } |
m_ahsan | 15:8c473836feba | 58 | else if(rsc == 2002){ |
m_ahsan | 15:8c473836feba | 59 | rsc = 0; |
m_ahsan | 15:8c473836feba | 60 | return -1; |
m_ahsan | 15:8c473836feba | 61 | } |
m_ahsan | 15:8c473836feba | 62 | //wait for response |
m_ahsan | 15:8c473836feba | 63 | return 0; |
m_ahsan | 15:8c473836feba | 64 | } |