static int u_close(struct pi_socket *ps) { LOG((PI_DBG_DEV, PI_DBG_LVL_DEBUG, "%s %d (%s).\n", __FILE__, __LINE__, __FUNCTION__)); RD_stop (); USB_close (); LOG((PI_DBG_DEV, PI_DBG_LVL_DEBUG, "%s %d (%s).\n", __FILE__, __LINE__, __FUNCTION__)); return close (ps->sd); }
int main(int argc, char **argv) { int c=0, ret = -1; //float i = 0; //float temp =0, hum =0; long time_mill_sec; char device_data_json[2048]; char* sdk_conf_File = NULL; char* dev_details_conf_File = NULL; DeviceDetails deviceDetail; struct timeval tv; printf("sampleApp - Starting ++ \n"); opterr = 0; while ((c = getopt (argc, argv, "c:d:")) != -1) { switch (c) { case 'c': sdk_conf_File = optarg; printf("sdk confFile1 = %s \n", sdk_conf_File); break; case 'd': dev_details_conf_File = optarg; printf("device confFile2 = %s \n", dev_details_conf_File); break; } } /* Register for signals*/ // signal(SIGINT, exit_app_function); signal(SIGTERM, exit_app_function); //Populate the device information into deviceDetail structure memset(&deviceDetail, 0, sizeof(DeviceDetails)); populate_device_details(&deviceDetail, dev_details_conf_File); if(sdk_conf_File) deviceDetail.sdkConfigFile = sdk_conf_File; printf("## deviceDetail.skip_registration = %d \n", deviceDetail.skip_registration); RD_start(); /* Main While Loop */ printf("sampleApp: Entering Application Main loop ++\n"); while(1){ printf("sampleApp: Loop : Accquire data -> serilaize data -> send data \n"); // DEMO -3 payload //update json payload gettimeofday(&tv, NULL); time_mill_sec = (tv.tv_sec) * 1000 + (tv.tv_sec) /1000; #if 0 i++; if(i > 9.0){ i = 0 ; temp = 0; hum = 0;}; temp = temp + i; hum = hum + (2*i); #else Sensor_Data SensorData = {{0}}; ret = getDfSensorData(&SensorData); if (ret == 0) #endif { df_Sensor_Data *tmp = (df_Sensor_Data*)(&SensorData); sprintf(device_data_json, "{\"messages\": [{\"data\": {\"temperature\": %f, \"humidity\": %f }, \"ts\": %ld, \"format\": \"json\"}]}", tmp->temperature, tmp->humidity, time_mill_sec); printf("sampleApp devicedata : %s \n size = %d \n", device_data_json, (int)sizeof(device_data_json)); ret = iot_device_sdk_data_send_v2 (&deviceDetail, device_data_json , sizeof(device_data_json), NULL, 0); if( ret < 0) printf("sampleApp: iot_device_sdk_data_send_v2 call failed \n"); else printf("sampleApp: iot_device_sdk_data_send_v2 call Successful \n"); } sleep(3); //Accquire Device Data //Serilize Device Data //Submit/Post Device Data //Check App exit Flag if(exit_flag) break; //Send keep-alive to CPOD } printf("sampleApp: Exited Application Main loop -- \n"); RD_stop(); //DeviceDetails if(deviceDetail.deviceType) free(deviceDetail.deviceType); if(deviceDetail.deviceMake) free(deviceDetail.deviceMake); if(deviceDetail.deviceModel) free(deviceDetail.deviceModel); if(deviceDetail.deviceFirmwareVer) free(deviceDetail.deviceFirmwareVer); if(deviceDetail.macAddress) free(deviceDetail.macAddress); if(deviceDetail.deviceSerialNum) free(deviceDetail.deviceSerialNum); if(deviceDetail.ipv4) free(deviceDetail.ipv4); if(deviceDetail.ipv6) free(deviceDetail.ipv6); if(deviceDetail.alt_id1) free(deviceDetail.alt_id1); printf("sampleAppApp Exiting --\n"); return 0; }