Ethernet radio dht22 data to plotly errors



  • Thanks to the organizers and participants of mysensors. I am trying to explore projects to motivate high school students. I want to transmit temp and humidity from a dht22 placed outdoors to an arduino uno with ethernet (wiznet 5100) shield and then plot to plotly (since that seems so cool). I am having trouble trying to merge several example sketches in order to do all of this.

    What works:

    1. Using sketches based on http://arduino-info.wikispaces.com/Nrf24L01-2.4GHz-HowTo my radios are successfully able to transmit and receive dht22 data (no ethernet shield connected and using the RF24 library suggested at the website)
    2. Separately, if I connect the dht22 directly to the arduino with the ethernet shield (no radios) I can successfully send data to plotly.

    Problem:
    When I try to combine the ethernet with the radio, I use the suggested pins A2, A1, etc and enable softspi using the mysensors libraries (this requires that I hide the rf24 library that I previously used for the successful communication test mentioned above). But I don't get far enough to upload the sketch, because of a compilation error

    YD_nRF24L01_Receive_DHT22.ino: In function 'void loop()':
    YD_nRF24L01_Receive_DHT22:98: error: void value not ignored as it ought to be
    

    which is associated with this part of the code (highlighting the "done = radio.read" line):

    void loop()   /****** LOOP: RUNS CONSTANTLY ******/
    {
      if ( radio.available() )
      {
    // Read the data payload until we've received everything
    bool done = false;
    while (!done)
    {
      // Fetch the data payload
      done = radio.read( dht22array, sizeof(dht22array) );
      Serial.print("temperature = ");
      Serial.print(dht22array[0]);
      Serial.print(" humidity = ");      
      Serial.println(dht22array[1]);
      Serial.println(millis());
      graph.plot(millis(), dht22array[0], tokens[0]);
      graph.plot(millis(), dht22array[1], tokens[1]);
      delay(15000);
    

    I have includes for SPI.h, MySensor.h, DigitalIO.h, and Ethernet.h

    Thanks to anyone for any help.


  • Admin

    @jhapper

    You shouldn't attach sensors to the gateway. SoftSPI should only be enabled on the gateway, not on sensors.

    Please try the humidity sensors available on http://www.mysensors.org
    (check that radio wiring is according to spec on site also)



  • Thank you for replying. I am using a DHT22 temperature and humidity sensor, as suggested on your site (which I have used to order many other components, so thanks for those links also). The sensor is currently not attached to the gateway (I only tried this once to be sure that I could send data to plotly, which worked).

    I am not understanding how to write the sketch to correctly read from the radio transmitter when my receiving radio is using softspi. I have the following code in the setup section:

      radio.begin();
      radio.openReadingPipe(1,pipe);
      radio.startListening();;
    

    But my immediate problem is the compilation error that says "void value not ignored as it ought to be"

    Thanks again.


  • Contest Winner

    @jhapper said:

    radio.begin();

    radio.begin();
    

    maybe you need to post your entire code...


  • Admin

    The MySensors library takes care of reading from radio. You shouldn't use the "low-level" functions of RF24.
    Please look at some the provided examples. and the API documentation on the main site.



  • Thank you both. In reply to BulldogLowell, here is the code for the receiver that is wired to the Wiznet shield with the radio using pins A0, A1, A2, 5, and 6.

    I copied and modified the receiver code from http://arduino-info.wikispaces.com/Nrf24L01-2.4GHz-HowTo

    /* MODIFIED FOR RECEIVING DHT22 TEMPERATURE AND HUMIDITY DATA RATHER THAN
    JOYSTICK VALUES AS STATED BELOW
    YourDuinoStarter Example: nRF24L01 Receive Joystick values
    
     - WHAT IT DOES: Receives data from another transceiver with
       2 Analog values from a Joystick or 2 Potentiometers
       Displays received values on Serial Monitor
     - SEE the comments after "//" on each line below
     - CONNECTIONS: nRF24L01 Modules See:
     http://arduino-info.wikispaces.com/Nrf24L01-2.4GHz-HowTo
       1 - GND
       2 - VCC 3.3V !!! NOT 5V
       3 - CE to Arduino pin 9--switched to pin 5
       4 - CSN to Arduino pin 10--switched to pin 6
       5 - SCK to Arduino pin 13--switched to pin A0
       6 - MOSI to Arduino pin 11--switched to pin A1
       7 - MISO to Arduino pin 12--switched to pin A2
       8 - UNUSED
       
     - V1.00 11/26/13
       Based on examples at http://www.bajdi.com/
       Questions: terry@yourduino.com */
    
    /*-----( Import needed libraries )-----*/
    #include <SPI.h>
    #include <nRF24L01.h>
    #include <RF24.h>
    //#include <MySensor.h>
    //#include <DigitalIO.h>
    
    #include <Ethernet.h>
    #include "plotly_streaming_ethernet.h"
    /*-----( Declare Constants and Pin Numbers )-----*/
    #define CE_PIN   5
    #define CSN_PIN 6
    
    #define nTraces 2
    char *tokens[nTraces] = {"2222222222", "3333333333"};
    // arguments: username, api key, streaming token, filename
    plotly graph("jameshapper", "1111111111", tokens, "BoyerCabinTempHum", nTraces);
    
    // NOTE: the "LL" at the end of the constant is "LongLong" type
    const uint64_t pipe = 0xE8E8F0F0E1LL; // Define the transmit pipe
    
    
    /*-----( Declare objects )-----*/
    RF24 radio(CE_PIN, CSN_PIN); // Create a Radio
    /*-----( Declare Variables )-----*/
    int dht22array[2];  // 2 element array holding DHT22 readings
    
    byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
    byte my_ip[] = { 222, 22, 222, 2 }; // google will tell you: "public ip address"
    
    void startEthernet(){
        Serial.println("... Initializing ethernet");
        if(Ethernet.begin(mac) == 0){
            Serial.println("... Failed to configure Ethernet using DHCP");
            // no point in carrying on, so do nothing forevermore:
            // try to congifure using IP address instead of DHCP:
            Ethernet.begin(mac, my_ip);
        }
        Serial.println("... Done initializing ethernet");
        delay(1000);
    }
    
    void setup()   /****** SETUP: RUNS ONCE ******/
    {
      graph.timezone = "America/New_York";
      graph.maxpoints = 250;
      
      Serial.begin(9600);
      delay(1000);
      Serial.println("Nrf24L01 Receiver Starting");
      radio.begin();
      radio.openReadingPipe(1,pipe);
      radio.startListening();;
      
      delay(3000);
      startEthernet();
      graph.fileopt = "extend"; // Remove this if you want the graph to be overwritten
      bool success;
      success = graph.init();
      if(!success){while(true){}}
      graph.openStream();
    
    }//--(end setup )---
    
    
    void loop()   /****** LOOP: RUNS CONSTANTLY ******/
    {
      if ( radio.available() )
      {
        // Read the data payload until we've received everything
        bool done = false;
        while (!done)
        {
          // Fetch the data payload
          done = radio.read( dht22array, sizeof(dht22array) );
          Serial.print("temperature = ");
          Serial.print(dht22array[0]);
          Serial.print(" humidity = ");      
          Serial.println(dht22array[1]);
          Serial.println(millis());
          graph.plot(millis(), dht22array[0], tokens[0]);
          graph.plot(millis(), dht22array[1], tokens[1]);
          delay(15000);
        }
      }
      else
      {    
          Serial.println("No radio available");
      }
    
    }//--(end main loop )---
    
    /*-----( Declare User-written Functions )-----*/
    
    //NONE
    //*********( THE END )***********
    

    I am still studying the api documentation, as suggested. Thanks again.



  • SOLVED

    I found that the older library I was using for the initial code returned a boolean for the read indicating whether or not data was still available in the register. In the newer mysensors library, I could change to use

    done = !radio.isAckPayloadAvailable();
    

    and everything is now working.


Log in to reply
 

Suggested Topics

  • 3
  • 4
  • 2
  • 2
  • 3
  • 2

21
Online

11.2k
Users

11.1k
Topics

112.5k
Posts