コード例 #1
0
void publishEventToIot (ManagedDevice* client){
	int rc =-1;
	rc =publishEvent_dm(client, "status","json", "{\"d\" : {\"temp\" : 34 }}", QOS0);
	if(rc== SUCCESS)
		printf("Event has been published \n");
	else
		printf("event publish failed \n");

}
コード例 #2
0
int main(int argc, char const *argv[])
{
	int rc = -1;

	//catch interrupt signal
	signal(SIGINT, signalHandler);
	signal(SIGTERM, signalHandler);

	char *configFilePath;

	if(isEMBDCHomeDefined()){

	    getSamplesPath(&configFilePath);
	    configFilePath = realloc(configFilePath,strlen(configFilePath)+15);
	    strcat(configFilePath,"device.cfg");
        }
	else{
	    printf("IOT_EMBDC_HOME is not defined\n");
	    printf("Define IOT_EMBDC_HOME to client library path to execute samples\n");
	    return -1;
        }

	rc = initialize_configfile_dm(configFilePath);
	free(configFilePath);

	if(rc != SUCCESS){
		printf("initialize failed and returned rc = %d.\n Quitting..", rc);
		return 0;
	}

	printf("Connecting to Watson Iot\n");
	rc = connectiotf_dm();

	if(rc != SUCCESS){
		printf("Connection failed and returned rc = %d.\n Quitting..", rc);
		return 0;
	}

	setCommandHandler_dm(myCallback);
	setManagedHandler_dm(managedCallBack );
	setFirmwareDownloadHandler(firmwareDownloadCallBack);
	setFirmwareUpdateHandler(firmwareUpdateCallBack);
	subscribeCommands_dm();

	char reqId[40];
	printf("\n publish manage ..\n");
	populateMgmtConfig();
	publishManageEvent(0,1,1, reqId);
	printf("\n Manage Event Exited: %s",reqId);

	/*printf("\n publish addLog ..\n");
	addLog(&client, "test","",1, reqId);
	printf("\n addLog Request Exit : %s",reqId);
*/
	while(!interruption)
	{
		printf("Publishing the event stat with rc ");
		rc= publishEvent_dm("status","json", "{\"d\" : {\"temp\" : 34 }}", QOS0);
		printf(" %d\n", rc);
		rc = yield_dm(100);
		sleep(2);
	}


	printf("Quitting!!\n");

	disconnect_dm();

	return 0;
}