Sparkfun8266 Wifi Shield + Arduino Due = WiFi Gateway



  • Hi Folks,
    I'm trying to convert an existing Ethernet Gateway (shield based w5100) into a WiFi gateway.

    I have the wifi shield working, can ping the Due etc.

    I've copied my relay code below the 8266 setup stuff, but I get an error when compiling:

    C:\Users\zach\Documents\Arduino\libraries\MySensors/MySensors.h:389:2: error: #error No forward link or gateway feature activated. This means nowhere to send messages! Pretty pointless.
    

    I guess it's because I have no:

    // Enable gateway ethernet module type
    #define MY_GATEWAY_W5100
    

    defined in my new sketch, but I'm not sure what to define. Will the w5100 work once the WiFi is up and running?

    I appreciate any help you folks can shed on this!

    Full sketch here:

    // Set the gateway type
    #define MY_GATEWAY_w5100
    
    // The port to keep open on node server mode
    #define MY_PORT 5003
    
    // How many clients should be able to connect to this gateway (default 1)
    #define MY_GATEWAY_MAX_CLIENTS 2
    
    
    #include <SoftwareSerial.h>
    #include <SparkFunESP8266WiFi.h>
    #include <MySensors.h>
    
    // Define relays
    #define RELAY_1  2            // 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 0            // GPIO value to write to turn on attached relay
    #define RELAY_OFF 1           // GPIO value to write to turn off attached relay
    
    // Replace these two character strings with the name and
    // password of your WiFi network.
    const char mySSID[] = "yourSSIDhere";
    const char myPSK[] = "yourPWDhere";
    
    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 - GW w/Relays", "1.0");
      
      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_BINARY);
      }
    }
    
    
    void loop()
    {
    
    }
    
    void receive(const MyMessage &message)
    {
      // We only expect one type of message from controller. But we better check anyway.
      if (message.type == V_STATUS) {
        // 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());
      }
    }
    


  • @zachflem Be sure that the #define is in capitals:

    #define MY_GATEWAY_W5100
    

    Otherwise it won't be correctly used by the compiler.


  • Mod

    @zachflem your setup is not compatible with the standard setups supported by mySensors.
    The sparkfun shield requires the esp8266 AT command set to communicate over wifi.

    I would advise you to use a different esp8266 board (E. G. NodeMCU) and program this directly as an Arduino.

    This should get you started: https://www.mysensors.org/build/esp8266_gateway



  • Ups yes I didn't realize that board won't work.

    I'm using a Wemos D1 R2 with support for OTA firmwar updates. I can share the code if you 're interested.



  • @yveaux Well that's just handy isnt it! So that shield was a waste of $12 bux!

    I've just ordered a prototyping shield and I'm going to have a go at building my own hack job esp-01 based shield.

    I've got an existing MEGA that I want to retrofit with wifi, rather than rebuilding the whole thing from scratch, and I'm using a LOT of I/O, which I havn't seen much of on the ESP stuff.

    Unless you can suggest an ESP based MEGA replacement with plenty (20+) I/O pins available??

    Cheers



  • @zachflem There are no ESP based boards wich such a high number of GPIOs that I know of. But there are some MEGA + ESP boards out there. I'm not sure they would work with Mysensors but may want to have a look.

    https://robotdyn.com/mega-wifi-r3-atmega2560-esp8266-flash-32mb-usb-ttl-ch340g-micro-usb.html

    https://www.instructables.com/id/Arduino-MEGA-2560-With-WiFi-Built-in-ESP8266/


  • Mod

    @zachflem I advise to keep your setup and your nodes simple. A gateway has a clear function and although gateway support for sensors has been added recently I would not try to fit everything into a single node.
    Reconsider your setup, using a simple esp8266+radio as your wifi gateway and one or more nodes providing the functionality you're looking for.



  • @yveaux well that's just not going to work for me, I'm trying to cut down on the amount of power supplies and random junk I have spread all over the place.


 

376
Online

8.0k
Users

8.8k
Topics

94.3k
Posts