/**
 * @name Starts the application
 * @brief Starts the application to publish data
 *
 * Establishes the connection with enableiot cloud
 */
int main(void) {
    puts("Sample program to publish data to IoT Cloud !!");

    srvSpec = (ServiceSpec *) parseServiceSpec("./serviceSpecs/temperatureServiceEnableIot.json");

    if (srvSpec){
        advertiseServiceBlocking(srvSpec, callback);
    }

    return 0;
}
Exemple #2
0
int main(int argc, char *argv[]) {
    ServiceSpec *specification = (ServiceSpec *)parseServiceSpec("../../examples/serviceSpecs/temperatureServiceMQTT.json");
    CommHandle *commHandle = createClient(specification);

    if (commHandle) {
        Context context;
        context.name = "topic";
        context.value = "temperature";
        commHandle->send("75 degrees", context);
        commHandle->unsubscribe("temperature");
        commHandle->subscribe("temperature");
    }
}
int main(void) {
    ServiceQuery *servQuery = (ServiceQuery *) parseServiceQuery("./temperatureServiceQueryMQTT.json");
    ServiceSpec *serviceSpec = (ServiceSpec *) parseServiceSpec("./temperatureServiceMQTT.json");
    /* Establish a handler for SIGALRM signals. */
    signal(SIGALRM, subDiscoveryCallback);
    /* Set an alarm to go off*/
    alarm(5);
    if (serviceSpec) {
        if (servQuery) {
            fprintf(stderr,"query host address %s\n",servQuery->address);
            fprintf(stderr,"query host port %d\n",servQuery->port);
            fprintf(stderr,"query service name %s\n",servQuery->service_name);
            printf("Waiting for the Service Upto 5 Seconds\n");
            discoverServicesBlocking(servQuery, subDiscoveryCallback);
        }
    }
    return 0;
}
/** Callback function. Once the service is discovered this callback function will be invoked
* @param servQuery left for future purpose, currently unused
* @param error_code the error code
* @param commHandle the communication handle used to invoke the interfaces
 */
void subCallback(ServiceQuery *servQuery, int32_t error_code, CommHandle *commHandle) {

    int (**receive)(void (*)(char *, Context));
    ServiceSpec *serviceSpec = (ServiceSpec *) parseServiceSpec("./serviceSpecs/thermostat-spec.json");
    if (serviceSpec) {
        advertiseService(serviceSpec);
        CommHandle *serviceHandle = createService(NULL, serviceSpec);
        mypublisher = commInterfacesLookup(serviceHandle, "publish");
        topic = serviceSpec->service_name;
    }
    if (commHandle != NULL) {
        receive = commInterfacesLookup(commHandle, "receive");
        if (receive != NULL) {
            while (1) {  // Infinite Event Loop
                (*receive)(clientMessageCallback);
                sleep(2);
            }
        } else {
            fprintf(stderr, "Interface lookup failed\n");
        }
    } else {
        fprintf(stderr, "Comm Handle is NULL\n");
    }
}