0

I'm learning Arduino's world, but knowing very little about C and C++.

I'm trying to achieve a little RF transmitter which should send the temperature and humidity from a DHT-11 sensor to a Raspberry Pi.

I'm using the RCSwitch library to send information with the Arduino, and the 433Utils library to receive it on the RPI.

Using those 2 libraries demos, I was able to send an integer, holding temperature or humidity information (mySwitch.send("00001010");), and read it on the RPI.

But how can I send both informations so that the RPI will know which one is the temperature and the humidity ?

I know I could just send both and assume the lowest is the temperature, but this would be very messy and not very rewarding.

EDIT :

Following Edgar's answer in https://arduino.stackexchange.com/a/52992/11604, I know write:

void send_string(const char *str){
    int i = 0;
    for (char *p = str; *p; p++ ) {     
        mySwitch.send((i<<8) + *p, 16);
        i++;
    }
}

void loop() {   
    delay(1000); 
    h=40.650;
    t=32.0078;  
    hic=33.586;     
    String x = "$H" + String(h) + "T" + String(t) + "HI" + String(hic); 
    send_string(x.c_str());
}

Works perfectly ! (see his complete answer for the RPI-side code)

  • 1
    mySwitch.send("T45H50");, mySwitch.send("[45;50]");, mySwitch.send("T45"); mySwitch.send("H50");... – Juraj Aug 21 '18 at 19:31
  • Are you really sending an integer, or are you sending an ASCII representation of the binary bits of an integer? – Majenko Aug 21 '18 at 21:31
  • The send() method take either an integer, a string byte representation or a tri-state code, I cannot send a string directly – Dan Chaltiel Aug 22 '18 at 6:30
1

The library you have chosen is not designed for transmitting information between nodes. It is intended for sending simple ON/OFF commands to RF-connected switches. Bending it to send data in the way you want would be difficult. Not impossible, but difficult.

Instead you should be considering a more suitable system, such as the popular RadioHead library. It appears to have Raspberry Pi support out of the box:

Raspberry Pi Uses BCM2835 library for GPIO http://www.airspayce.com/mikem/bcm2835/ Currently works only with RH_NRF24 driver or other drivers that do not require interrupt support. Contributed by Mike Poublon.

Alternatively a small Arduino as an interface between the RF module and the Pi may be another option.

  • I think this library is what I was looking for, thanks ! But I don't understand your last sentence, in what is this different than what I'm doing ? – Dan Chaltiel Aug 22 '18 at 6:35
  • Actually, RadioHead is far too complicated when you don't fully understand what you are doing (hope I'll get it someday). I found a very good answer with RCSwitch [arduino.stackexchange.com/questions/52989/…. – Dan Chaltiel Aug 22 '18 at 12:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.