Project

General

Profile

using different type of value on payload definition

Added by christrabin about 6 years ago

hello

i try to load two sketches on jeenodes v6. i have no problem with the first dht_demo but on the second on the last row, i have this error

 receiverheorthe_ino.ino: In function 'void loop()':
 receiverheorthe_ino:59: error: no match for 'operator[]' in 'Solartx[i]

i thinks its because in the first sketches i define the payload like this

typedef struct {
      int room;           ////code 1 : rheothe code 2: test room name
          int tempsolar;    // Temperature reading
          int humiditysolar;    // Actually humidity reading 
          float co2solar; //c02 reading
 } PayloadSolar;

 PayloadSolar Solartx;

and in the second, when i want to write the array, its impossible to have the lenght. i try different way on the net but i’m too newbie. i have try to convert the float in integer by multiplicate by 100 or anything else but i dont find the way to have an integer. i post my sketches if someone have an idea, this is my break point in my project….

rf12_sleep(-1);     //wake up RF module
    Solartx = *(PayloadSolar*) rf12_data;
    int i;

    for (int i= 0; i < (sizeof(Solartx)/sizeof(int))-1; i++)
    {
      Serial.write(Solartx[i]);

Replies (2)

RE: using different type of value on payload definition - Added by jcw about 6 years ago

If you change your code to these lines:

PayloadSolar* Solartx;
Solartx = (PayloadSolar*) rf12_data;

Then you can access the contents as “Solartx->room”, etc:

Serial.println(Solartx->room);
Serial.println(Solartx->tempsolar);
Serial.println(Solartx->humiditysolar);
Serial.println(Solartx->co2solar);

If all you want is to print the bytes, then you don’t have to do the casting and pointer stuff, just print “rf12_data[i]” values.

Explanation: rf12_data is a pointer to bytes. The “(PayloadSolar*)” turns it into a pointer to a PayloadSolar struct. Access to the fields via a pointer to a struct must use the “ptr->field” notation, i.s.o. “value.field”.

Welcome to the“wonderful” world of a 45-year old programming language…

RE: using different type of value on payload definition - Added by christrabin about 6 years ago

hi

i have no error now but it should too lucky o_Ô….

Nothing arrive in the serial monitor. In the dth_demo2 stetches, i read the analog pin in port 1 with the code below. I put on a mg811 sensor of c02 http://www.zartronic.fr/capteur-de-gaz-co2-mg811-p-394.html. I use this code http://www.veetech.org.uk/CO2\_Monitor\_Sketch\_2\_Operation.txt and its ok when i put the sensor alone on arduino.

i use an external power source (http://www.petervis.com/Raspberry\_PI/Breadboard\_Power\_Supply/YwRobot\_Breadboard\_Power\_Supply.html) for him and put only the data wire on port 1 A.

i have two things that i couldn’t fix:

-the dataco2 give hieroglyphic typewriter instead of the voltage
-i load the stetches receive and send by felix of lowpowerlab.com. When i leave the two sensors dth11 ang mg811, the jeenodes dont responded. i leave the dth11 and full disconnect the mg811 and the jeenodes communicate.

so, i thing the mg811 is the raison of this failing but i don’t unterstand why. a great “MERCI” for you.

in “apparte”, i appreciate your job and the rapidity and the quality of service that i have when i command on your shop

void setup () 
{
  Csolar.mode2(INPUT);
  rf12_initialize(NodeID,freq,network); // Initialize RFM12 with settings defined above 
  Serial.begin(57600);

}

void loop () 
{
  //read temp and humidity from sensor DTH11

  Solartx.room=2;
  Serial.println(Solartx.room); 
  int t, h;
  if (dht.reading(t, h)) 
  {
  Solartx.tempsolar = (t/10);
  Solartx.humiditysolar=(h/10);
  }
 Serial.println(Solartx.tempsolar);
 Serial.println(Solartx.humiditysolar);

 // Read co2 data from sensor
 int dataco2=Csolar.anaRead();// voltage input from sensor

 Serial.println  (dataco2);
 float voltage = dataco2/204.6;
    (1-2/2)