123
Dependencies: MQTTSN
Diff: registration.h
- Revision:
- 15:8c473836feba
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/registration.h Tue Aug 06 05:32:43 2019 +0000 @@ -0,0 +1,64 @@ + +int Registration(MQTTSN::Client<MQTTSNUDP, Countdown> *client, MQTTSNUDP* ipstack, MQTTSN_topicid& topicid) +{ + //Create AE + //Mendatory resources: Operation, To, From, Request Identifier ,Resource Type, Content + //Resource Specific Attributes [M]: App-ID, requestReachability, supportedReleaseVersions + // [0]: PointofAccess, ResourceName + Request R1; + AE_ID = "S"; //Initial registration + //struct Mendatory m1; + R1.To = CSE_ID; + R1.From = AE_ID; + R1.Request_Identifier = "createAE11"; + R1.Resource_Type = 2; + R1.Operation = 1; + + //struct CreateAE CAE; + CAE.resourceName = MQTT_CLIENT_ID; + CAE.requestReachability = true; + CAE.App_ID = "A01.com.sensor011"; + //buffer = Create_AE(); + lcl = false; + buf = Create_Req(R1); + printf("string in buf is %s\n",buf); + //buf[0] = '\0'; + + + //PUBLISH + + if ((rc = publish(client, ipstack, topicid)) != 0) + printf("rc from MQTT Publish is %d\n", rc); + else + printf("Published Buffer: %s to Topic %s\n",buf, MQTT_TOPIC); + + while(1) + { + + client->yield(4000); + /*if(isMessageArrived) { + isMessageArrived = false; + // Just print it out here. + //printf("\r\nMessage arrived:\r\n%s\r\n", messageBuffer); + //process_msg(); + + //free(messageBuffer); + } */ + if(rsc != 0){ + //reg_resp = true; + printf("rsc = %d\n",rsc); + break; + } + else rsc = 0; + } + if(rsc == 2001 ){ + rsc = 0; + return 0; + } + else if(rsc == 2002){ + rsc = 0; + return -1; + } + //wait for response + return 0; +}