These above are the codes.
demo_printf("Sampled NodeId %d %lu\n", NodeId,"Sampled SignalSTR %d %lu\n", Signal,"Sampled FirmwareVER %d %lu\n", FirmwareVER,"Sampled battery %f %lu\n", batt,timestamp);
kaa_error_t error = kaa_logging_add_record(
kaa_client_get_context(kaa_client)->log_collector,
log_record, NULL);
以下是错误。我不明白错误是什么。到目前为止,C语言的新功能...似乎对于我的浮点变量,我不能使用'%'来执行我的random()函数。以下是错误:
/home/pi/try/client/c/src/kaa_demo.c: In function ‘send_temperature’:
/home/pi/try/client/c/src/kaa_demo.c:72:22: error: invalid operands to binary % (have ‘int’ and ‘double’)
float batt = rand() % 5.0;
^
/home/pi/try/client/c/src/kaa_demo.c:73:21: error: invalid operands to binary % (have ‘int’ and ‘double’)
float cel = rand() % 5.0;
^
/home/pi/try/client/c/src/kaa_demo.c:74:20: error: invalid operands to binary % (have ‘int’ and ‘double’)
float wt = rand() % 5.0; // kaa_logging_data_collection_t is the structure defined to contain temperature and time_stamp
^
/home/pi/try/client/c/src/kaa_demo.c:81:12: error: ‘kaa_logging_data_collection_t’ has no member named ‘NodeId’
log_record->NodeId = kaa_string_copy_create("Screws");
^
/home/pi/try/client/c/src/kaa_demo.c:82:15: error: ‘kaa_logging_data_collection_t’ has no member named ‘SignalSTR’
log_record->SignalSTR = Signal;
^
/home/pi/try/client/c/src/kaa_demo.c:83:12: error: ‘kaa_logging_data_collection_t’ has no member named ‘FirmwareVER’
log_record->FirmwareVER = kaa_string_copy_create("Linux KIDS");
^
/home/pi/try/client/c/src/kaa_demo.c:84:12: error: ‘kaa_logging_data_collection_t’ has no member named ‘OnlineStat’
log_record->OnlineStat = status;
答案 0 :(得分:0)
您的前三个错误是由模数运算符不能与实数一起使用的结果。并且您使用实数来划分rand()的输出,它是整数。这里解释的主题是: (Why does modulus division (%) only work with integers?)
请您分享结构(kaa_logging_data_collection_t)元素: 如果你可以的话。那么只有任何人都可以确定为什么会出现这些错误。