Gateway ethernet Raspberry + sensors



  • Hello,

    I have developed a sensor based on Arduino pro mini 3.3v with a DHT 22, an 18b20, a door contact and a battery check. Apart from the battery check which is not satisfactory, everything works very well. This sensor communicates (nrf24 ...) with a gateway ethernet (Mysgw) based on a raspberry. The Gateway communicates with the Openhab 2.0 controller (Openhabianpi). I also have an older generation TellStick module on the controller that works well.
    My questions are: Is it possible to add a DHT22 on the gateway? Is it possible to use the Arduino code on mysgw.cpp? How to communicate between the probe part and the gateway part on the gateway?
    Thank you for your answers and especially for your work.


  • Mod

    I don't know about adding sensors on raspberry gw, but you can for sure use an UNO as serial gateway connected via usb with the sensors on it


  • Contest Winner

    @mimaret never tried by myself but having a quick look to the code this seems to be possible. When compiling under a raspberry all the arduino's GPIO functions are emulated in a transparent way looks like (https://github.com/mysensors/MySensors/blob/development/drivers/RPi/RPi.h)



  • Thank you for your answers. I wanted to avoid an Arduino. I think I will install the gateway on the OpenHabianpi Raspi and use an arduino as a sensor.



  • Hi, i have tryed to put some code directly in examples_linux/mysgw.cpp .

    The code run and work:

    ...
    
    #include <MySensors.h>
    
    #define ARDUINO 100
    // This space is intended to be used to include arduino libraries
    
    #include <MySensors.h>
    //#include <DHT.h>
    
    
    //#define DIGITAL_INPUT_SENSOR 7   // GPIO4
    #define CHILD_ID 1   // Id of the sensor child
    #define SLEEP_TIME 5000
    //MyMessage msg(CHILD_ID, V_STATUS);
    #define DEBUG true
    
    //array of pin used for input button
    static const short int digital_input_pin[] = {7,11,13,15};
    
    bool Tripped[sizeof(digital_input_pin)/sizeof(digital_input_pin[0])];
    bool State[sizeof(digital_input_pin)/sizeof(digital_input_pin[0])];
    MyMessage msg[sizeof(digital_input_pin)/sizeof(digital_input_pin[0])];
    
    #undef ARDUINO
    
    void setup()
    {
            // Setup locally attached sensors
            for(unsigned int i=0; i < sizeof(digital_input_pin)/sizeof(digital_input_pin[0]); i ++){
                    if (DEBUG == true){
                            Serial.print("init:");
                            Serial.print(i);
                            Serial.println(digital_input_pin[i]);
                    }
                    pinMode(digital_input_pin[i], INPUT);
                    State[i] = loadState(CHILD_ID+i)?true:false;
                    Tripped[i] = false;
                    msg[i].sensor = i;
                    msg[i].type = V_STATUS;
            }
    }
    
    void presentation()
    {
            // Present locally attached sensors here
            sendSketchInfo("Arduino Jarvis", "0.9");
            for(unsigned int i=0; i < sizeof(digital_input_pin)/sizeof(digital_input_pin[0]); i ++){
                    present (CHILD_ID+i, S_BINARY);
            }
    }
    
    void loop()
    {
            for(unsigned int i=0; i < sizeof(digital_input_pin)/sizeof(digital_input_pin[0]); i ++ ){
                    bool tripped = digitalRead(digital_input_pin[i]);
                    if (Tripped[i] != tripped){
                            Tripped[i] = tripped;
                            State[i] = ! State[i];
                            send(msg[i].set(State[i]));
                            saveState(CHILD_ID+i, State[i]);
                            if (DEBUG == true){
                                    Serial.print("send to mg: ");
                                    Serial.print(State[i]);
                                    Serial.print(", for pin: ");
                                    Serial.println(digital_input_pin[i]);
                            }
                    }
            }
            // Sleep until interrupt or timeout
            // TODO: Just one pin interrrupt !
            sleep(digitalPinToInterrupt(digital_input_pin[0]), CHANGE, SLEEP_TIME);
    }
    

    I don t know at this time how to add Arduino library like DHT.h, but i have not tryed.

    I have a question, someone know how to switch GPIO intput to GPIO.PUD_UP (pullup) ?


  • Mod

    All you are looking for is the examples and in the build page of the main site


Log in to reply
 

Looks like your connection to MySensors Forum was lost, please wait while we try to reconnect.