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);  

Below are the errors. I dont understand what the errors are. New to C language so far...It seems like for my float variables , i cannot use '%' to carry out my random() function. Below are the errors :

/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;
  • Would like to clarify some of these errors with you and what do they mean ? @Mikel F , sorry for the inconvenience caused. – darren sim Jan 11 '17 at 04:45
  • 1
    I would hope that `'X' has no member named 'Y'` is pretty straightforward... – user253751 Jan 11 '17 at 04:49
  • But i did add the members into the log record where the kaa_logging_data_collection_t saves them all up. – darren sim Jan 11 '17 at 05:05
  • How about should i do it for the 'no member' error for my codes ? – darren sim Jan 11 '17 at 05:18
  • You have used batt,cel,wt as float and doing rand() operation and that too with an additional usage of "%" operator. Guess that wont work out. Please check the usage of rand() function. – Vimal Bhaskar Jan 11 '17 at 05:22
  • Since you did add members into the log record, it is possible that the program has not been compiled properly. Did you compile the entire program with an updated object code? – mahesh Rao Jan 11 '17 at 05:29
  • i have changed my codes to : fmod(rand(), (5.0 - 3.0 + 1)) + 3.0; for the 3 because all of them are around the same values. but funnny is that i only have errors for batt but not for wt and cel – darren sim Jan 11 '17 at 05:29
  • Does the 'has no member' errors osos dependent on the error you told me – darren sim Jan 11 '17 at 05:30
  • On making said changes, do all the errors still remain ? if not, which of them do ? – mahesh Rao Jan 11 '17 at 05:38
  • The errors that occurred are self explanatory. The modulo operator is integer based, hence you use `fmod`. `rand` is generally initialized via `srand` but, if it isn't, you have set the random number seed to 1. The **has no member** error also tells you that the compiler isn't able to find that particular member. This may occur if the compiler is not referring to the desired structure, the object code of the program has not been updated or the structure actually does not have those members. – mahesh Rao Jan 11 '17 at 05:48
  • im debugging errors by errors. i first editted '%' for all the batt,cel and wt because its a common error. But all of them are of the same method , so i searched on the right rand function and then i applied to all of them. but then i only got error for batt for : incompatible implicit declaration of built-in function ‘fmod’ whereas not for wt and cel – darren sim Jan 11 '17 at 05:48
  • Did you include math.h header ? – mahesh Rao Jan 11 '17 at 05:54
  • @darrensim How are we supposed to know whether the members are in the structure if we can't see the structure? But I assume they aren't in the structure because the compiler says they aren't. – user253751 Jan 11 '17 at 06:20

1 Answers1

0

Your first three errors are are caused by the fact that modulus operator doesn't work with real number. and you are using real number to divide the output of rand() which is integer. The topic is explained here: (Why does modulus division (%) only work with integers?)

Can you please share the structure (kaa_logging_data_collection_t) elements: If you can. then only anyone can be sure that why these errors are coming here.

Community
  • 1
  • 1
Vishwajeet Vishu
  • 492
  • 3
  • 16
  • i couldnt find this function or structure..isit possible like its being pointed to another variable or address containing the temperature and timestamp? – darren sim Jan 11 '17 at 07:45
  • 1
    You need to find the structure, because then only you will be sure what it contains are and how to access those elements otherwise you wont be able to access them properly. It might be possible that these elements are there in the structure but they are being accessed through some other pointer or DE-reference variable. Just like before using a machine you should know what are its components and what they do individually, You can look for the definition of this structure in custom header files. Hope this helps – Vishwajeet Vishu Jan 11 '17 at 09:21
  • Found it ! haha but now am stucked with another problem with something called avro_Reader. do not worry , after i get 15 reputations , i will be back to upvote for you ! – darren sim Jan 11 '17 at 09:38
  • ok try to sort it out, if it does not go away. you can alwaysshare it with us – Vishwajeet Vishu Jan 11 '17 at 09:42