0
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;
4

1 回答 1

0

您的前三个错误是由于模运算符不适用于实数这一事实引起的。并且您正在使用实数来划分 rand() 的输出,它是整数。该主题在这里解释:(为什么模除(%)仅适用于整数?

您能否分享结构(kaa_logging_data_collection_t)元素:如果可以。那么只有任何人才能确定为什么这些错误会出现在这里。

于 2017-01-11T05:49:37.257 回答