예제 #1
0
int main(void)
{
    long long unsigned int loopcount = 0, errorcount = 0;
    char read_str[32];
    char loop_str[16];
    char error_str[16];
    const uint8_t op_count = 4;
    exo_op ops[op_count];

    exo_init(VENDOR, MODEL, SERIAL);

    for (int i = 0; i < op_count; i++){
        exo_op_init(&ops[i]);
    }

    // only need to setup subscribe once
    exo_subscribe(&ops[1], "command", read_str, 32);
    
    while(1)
    {
        if (loopcount % 100 == 0){
            // prepare data to write
            snprintf(loop_str, 15, "%llu", loopcount);

            // queue write operation
            exo_write(&ops[2], "uptime", loop_str);
        }

        // perform queued operations until all are done or failed
        while(exo_operate(ops, op_count) != EXO_IDLE);

        // check if ops succeeded or failed
        for (int i = 1; i < op_count; i++){
            if (exo_is_op_finished(&ops[i])) {
                if (exo_is_op_success(&ops[i])) {
                    if (exo_is_op_read(&ops[i]) || exo_is_op_subscribe(&ops[i])) {
                        printf("[SUCCESS] got '%s' = `%s`\n", ops[i].alias, ops[i].value);
                    } else if (exo_is_op_write(&ops[i])) {
                        printf("[SUCCESS] set '%s' = `%s`\n", ops[i].alias, ops[i].value);
                    } else {
                        printf("[WARNING] something succeeded, but I don't know what\n");
                    }
                } else {
                    printf("[ERROR] on '%s'\n", ops[i].alias);
                    printf("        error count is now %llu\n", errorcount);

                    // queue a write to error count next time
                    snprintf(error_str, 15, "%llu", errorcount);
                    exo_write(&ops[3], "errorcount", error_str);
                }

                exo_op_done(&ops[i]);
            }
        }

        nanosleep((struct timespec[]){{0, 500000000}}, NULL);
        loopcount++;
    }
예제 #2
0
int main()
{
	int sockRead, sockWrite, sockSub;
	int len;
	int opStatus = -1;
	int i;
	date_time_t curDateTime;

	
	exo_init(	"hackntu2016",
				"iot1001",
				"1A:01:00:00:00:03");

	exosite_pal_get_current_date_time(&curDateTime);

	while(1)
	{
		printf("start to write data to cloud\r\n");
		sockWrite = exo_write(	"AccXRaw_ICM20648",
								"3.5",
								write_callback);

		sockRead = exo_read("LED1Status_Board",
							read_callback);

		sockSub = exo_subscribe("LED1Status_Board",
								&curDateTime,
								subscribe_callback);


		printf("loop start\r\n");
		exo_loop_start();

		exosite_pal_get_current_date_time(&curDateTime);

	
		printf("loop end\r\n");
	}

	return 0;
}