MyController (Ubuntu) + Ethernet Gateway + Relay Board



  • Hi folks,

    I'm trying to get MyController to see my Ethernet Gateway and the 4xRelay board that's connected to it.

    I can use the relay board with a simple webserver sketch, seperate to mycontroller, so I can only assume that the wiring is correct.

    I can ping the MySensors(2.1.1) Gateway from my laptop and from the ubuntu server.

    I can add the Gatewat to MyController and it shows status as "Connected Successfully" and a nice green tick.

    And this is where I get stuck.

    Either I am not doing something correctly, or for some reason, my relay board isn't showing up/available.

    I am currently using sketches with as little modification as possible, gleaned directly from tutorials etc.

    Any advice greatly appreciated.

    TIA

    Zach

    Sketch Here:

    // Enable debug prints to serial monitor
    #define MY_DEBUG 
    
    // Enable gateway ethernet module type 
    #define MY_GATEWAY_W5100 
    
    // IP Connection
    #define MY_IP_ADDRESS 10,0,0,201                              // If this is disabled, DHCP is used to retrieve address
    #define MY_PORT 5003                                          // The port to keep open on node server mode / or port to contact in client mode
    #define MY_MAC_ADDRESS 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED     // MAC Address, can be anything, but must be unique on the network
    
    // Include the various Libraries
    #include <SPI.h>
    #include <Ethernet.h>
    #include <MySensors.h>
    
    // Define relays
    #define RELAY_1  6            // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
    #define NUMBER_OF_RELAYS 4    // Total number of attached relays
    #define RELAY_ON 1            // GPIO value to write to turn on attached relay
    #define RELAY_OFF 0           // GPIO value to write to turn off attached relay
    
    
    void before() { 
      for (int sensor=1, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS;sensor++, pin++) {
        // Then set relay pins in output mode
        pinMode(pin, OUTPUT);   
        // Set relay to last known state (using eeprom storage) 
        digitalWrite(pin, loadState(sensor)?RELAY_ON:RELAY_OFF);
      }
    }
    void setup()
    {
    }
    
    void presentation()  
    {   
      // Send the sketch version information to the gateway and Controller
      sendSketchInfo("Audry - Gateway w/Relays", "0.1");
    
      for (int sensor=1, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS;sensor++, pin++) {
        // Register all sensors to gw (they will be created as child devices)
        present(sensor, S_LIGHT);
      }
    }
    
    void receive(const MyMessage &message) {
      // We only expect one type of message from controller. But we better check anyway.
      if (message.type==V_LIGHT) {
         // Change relay state
         digitalWrite(message.sensor-1+RELAY_1, message.getBool()?RELAY_ON:RELAY_OFF);
         // Store state in eeprom
         saveState(message.sensor, message.getBool());
         // Write some debug info
         Serial.print("Incoming change for sensor:");
         Serial.print(message.sensor);
         Serial.print(", New status: ");
         Serial.println(message.getBool());
       } 
    }
    
    void loop() {
    }
    

  • Plugin Developer

    @zachflem Can you see a node 0? Select your gateway and run Discover


Log in to reply
 

Suggested Topics

  • 17
  • 9
  • 4
  • 9
  • 2
  • 1

1
Online

11.4k
Users

11.1k
Topics

112.7k
Posts