// This function pushes changes to the cloud for two specific column names, and pushes new information every time without updating previous records
void updateOnParse(const char *column, int value)//, const char *healthColumn, int healthValue)
{	
	
	ParseClient client = parseInitialize("TSexah1prtbhpF6w4dellQ2XYWyk2bqcljOiElrN", "xLnvnzcTMO1w9MwuFNBTO6hLjOtnKmZn4iz4SBnu");
	char strValue[4];
	char strColumn[4];
	//char IDvalue[10];
	char pathLabel[4];
	char grabbed_string[] = "1111111111";
	sprintf(strValue, "%d", value);

	char data[100] = "{ \"";
	
	strcat(data, column);
	strcat(data, "\": ");
	strcat(data, strValue);
	strcat(data, " }");
	
	parseSendRequest(client, "POST", "/1/functions/put_objectID", "{\"value\":\"echo\"}", myCloudFunctionCallback);
	strncpy(grabbed_string, copied_string+11,10);
	//need a way to retrieve the object ID so that these things can be associated
	strcat(pathLabel, "/1/classes/Bulb/");
	strcat(pathLabel, grabbed_string);

	printf("%s\n", pathLabel);
	sleep(1); //putting this here lets other stuff run... loks like parse isn't accepting stuff
	printf("lightbulb::updateOnParse(): Trying data  %s\n", data);
	parseSendRequest(client, "POST", pathLabel, data, NULL);
	printf("lightbulb::updateOnParse(): Pushed data  %s\n", data);
	
}
/*
* main function to handle Parse GET/CREATE/DELETE/UPDATE/QUERY request
* @params
* -v - http verb
* -e - http endpoint
* -d - request body
* -p - parameters (used only for Parse query)
* -i - command to get installation id
*/
int main(int argc , char **argv) {
  char c;
  extern char* optarg;

  yunReadProvisioningInfo();

  ParseClient client = parseInitialize(g_cAppID,g_cClientKey);

  if(g_cInstallationID[0] != '\0') {
	parseSetInstallationId(client, g_cInstallationID);
  }
  if(g_cSessionToken[0] != '\0') {
	parseSetSessionToken(client, g_cSessionToken);
  }

  while((c=getopt(argc,argv,"v:e:d:p:is"))!=-1){
    switch(c){
      case 'v': // http verb
      if(!(verb=strdup(optarg))){
        return -1;
      }
      break;
      case 'e': // http endpoint
      if(!(endpoint=strdup(optarg))){
        return -1;
      }
      break;
      case 'd': // request body
      if(!(data=strdup(optarg))){
      }
      fprintf(stderr, "data = '%s'\n", data);
      break;
      case 'p': // parameters
      if(!(params=strdup(optarg))){
      }
      break;
      case 'i':
      arduinoGetInstallationId(client);
      exit(0);
      case 's':
      arduinoGetSessionToken(client);
      exit(0);
    }
  }

  if (strncmp("GET", verb, 3) == 0) {
    data = params;
  }

  if (client) {
    if (!params) {
      parseSendRequest(client, verb, endpoint, data, arduinoCallHandler);
    } else {
      parseSendRequest(client, verb, endpoint, params, arduinoQueryHandler);
    }
  }

  exit(0);
}
// This function pushes data onto the Parse Application in cloud. It is invoked by updateIntensity().
void *threadPushNotifications()
{
	pthread_detach(pthread_self());
	//ParseClient client = parseInitialize("kayWALfBm6h1SQdANXoZtTZqA0N9sZsB7cwUUVod", "7Nw0R9LTDXR7lRhmPsArePQMralFW8Yt7DL2zWTS");
	ParseClient client = parseInitialize("TSexah1prtbhpF6w4dellQ2XYWyk2bqcljOiElrN", "xLnvnzcTMO1w9MwuFNBTO6hLjOtnKmZn4iz4SBnu");
	char *installationId = parseGetInstallationId(client);

	/* We need to set the InstallationId forcefully. Setting installationId to dataUUID based on null string is incorrect
	logic as there is a possibility that the installationId was previously set to some junk value.
	Typically this will break the push notification subscription */
	parseSetInstallationId(client, dataUUID);
	printf("lightbulb::threadPushNotifications():New Installation ID set to : %s\n", installationId);
	printf("lightbulb::threadPushNotifications():Installation ID is : %s\n", installationId);	
	parseSetPushCallback(client, healthCallback);
	parseStartPushService(client);
	parseRunPushLoop(client);
	printf("Somewhere in threadPushNotifications()\n");
	
	
}
Example #4
0
/**
 * \brief Main application function.
 *
 * Application entry point.
 *
 * \return program return value.
 */
int main(void)
{
	char ssid[] = "YOUR_NETWORK_ID";
	char pw[] = "YOUR_NETWORK_PASS";
	/* 0 - no security, 1 - WEP, 2 - WPA */
	int secType = 2;

	/* Initialize the board. */
	system_init();

	/* Initialize the UART console. */
	configure_console();
	printf(STRING_HEADER);

	/* Configure Non-Volatile Memory */
	configure_nvm();

	if (LOCAL_PARSE_SUCCESS != initWifiModule()) {
		printf("main / initWifiModule Error !!!!!\r\n");
		return -1;
	}

	loadSettingsOrProvisionBoard(ssid, pw, secType);
	while (1) {
		if (M2M_WIFI_MODE_STA == localParseEventLoop(NULL)) {
			printf("main / WiFi connection is done\r\n");
			break;
		}
	}

	parseClient = parseInitialize(YOUR_APP_ID, YOUR_CLIENT_ID);
	if (parseClient) {
		printf("main / parseClient 0x%x\r\n", parseClient );

		while (1) {
			parseRunPushLoop(parseClient);
		}
	}

	return 0;
}
Example #5
0
int main(int argc, char *argv[])
{
    ParseClient client = parseInitialize("VOB4wXj2mGOjJaqzdhkM701n2ahTSRMqZW6QQ8XU", "XCPG2OTVrapoymNGS5XGQIhsRM3F2tnVUgaceyec");
    
    int childpid = fork();
    
    if (childpid == 0)
    {
        while (1)
        {
            float currentTemp = getTemperature();
            char data[256];
            sprintf(data, "{ \"value\": %f }", currentTemp);
            parseSendRequest(client, "POST", "/1/classes/Temperature", data, NULL);
        }
    }
    
    printf("CHILDPID: %d\n", childpid);
    
    return 0;
}
int main(int argc , char **argv) {
  char c;

  int isYun = yunReadProvisioningInfo();

  // process pre init options
  while((c=getopt(argc,argv,":a:k:x:y:v:e:d:p:ish"))!=-1){
    switch(c) {
        case 'h':
            displayHelp();
            exit(0);
        case 'a':
            strncpy(g_cAppID, optarg, sizeof(g_cAppID));
            break;
        case 'k':
            strncpy(g_cClientKey, optarg, sizeof(g_cClientKey));
            break;
        case 'x':
            strncpy(g_cInstallationID, optarg, sizeof(g_cInstallationID));
            break;
        case 'y':
            strncpy(g_cSessionToken, optarg, sizeof(g_cSessionToken));
            break;
        case 'v':
        case 'e':
        case 'd':
        case 'p':
        case 'i':
        case 's':
            // these we want to process later
            break;
        case ':':
          fprintf(stderr, "%s: option '-%c' requires an argument\n", argv[0], optopt);
          exit(0);
        case '?':
          fprintf(stderr, "%s: option '-%c' is not recognized \n", argv[0], optopt);
          exit(0);
        default:
          fprintf(stderr, "%s: option '-%c' is not implemented\n", argv[0], optopt);
          exit(0);
    }
  }

  if (g_cAppID[0] == '\0') {
    fprintf(stdout, "{\"error\":\"missing application id\"}\n");
    exit(0);
  }
  if (g_cClientKey[0] == '\0') {
    fprintf(stdout, "{\"error\":\"missing client key\"}\n");
    exit(0);
  }

  ParseClient client = parseInitialize(g_cAppID,g_cClientKey);

  if(g_cInstallationID[0] != '\0') {
	parseSetInstallationId(client, g_cInstallationID);
  }
  if(g_cSessionToken[0] != '\0') {
	parseSetSessionToken(client, g_cSessionToken);
  }

  // process post init options
  optreset = 1;
  optind = 1;

  while((c=getopt(argc,argv,":a:k:x:y:v:e:d:p:ish"))!=-1){
    switch(c){
      case 'v': // http verb
        if(!(verb=strdup(optarg))){
            return -1;
        }
        break;
      case 'e': // http endpoint
        if(!(endpoint=strdup(optarg))){
            return -1;
        }
        break;
      case 'd': // request body
        if(!(data=strdup(optarg))){
        }
        break;
      case 'p': // parameters
        if(!(params=strdup(optarg))){
        }
        break;
      case 'i':
        arduinoGetInstallationId(client);
        exit(0);
      case 's':
        arduinoGetSessionToken(client);
        exit(0);
    }
  }

  if (strncmp("GET", verb, 3) == 0) {
    data = params;
  }

  if (client) {
    if (!params) {
      parseSendRequest(client, verb, endpoint, data, arduinoCallHandler);
    } else {
      parseSendRequest(client, verb, endpoint, params, arduinoQueryHandler);
    }
  }

  exit(0);
}