Poor Signal range from sensor to gateway



  • I am hoping someone here could possibly shed some insight as to what steps to take next. I am having issues getting a sensor that is approximately 15ft (3m) from the gateway to communicate. It appears it will not communicate with the gateway unless it is approximately 3ft (1m) away from the gateway. Here is some background of my environment:

    Gateway:
    itead studio iBoard
    NRF24L01+ (Added 4.7u Decoupling Capacitor, didn't make a difference)
    Version 1.5
    Sketch:

    /**
     * The MySensors Arduino library handles the wireless radio link and protocol
     * between your home built sensors/actuators and HA controller of choice.
     * The sensors forms a self healing radio network with optional repeaters. Each
     * repeater and gateway builds a routing tables in EEPROM which keeps track of the
     * network topology allowing messages to be routed to nodes.
     *
     * Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
     * Copyright (C) 2013-2015 Sensnology AB
     * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
     *
     * Documentation: http://www.mysensors.org
     * Support Forum: http://forum.mysensors.org
     *
     * This program is free software; you can redistribute it and/or
     * modify it under the terms of the GNU General Public License
     * version 2 as published by the Free Software Foundation.
     *
     *******************************
     *
     * REVISION HISTORY
     * Version 1.0 - Henrik EKblad
     * Contribution by a-lurker and Anticimex, 
     * Contribution by Norbert Truchsess <norbert.truchsess@t-online.de>
     *
     * 
     * DESCRIPTION
     * The EthernetGateway sends data received from sensors to the ethernet link. 
     * The gateway also accepts input on ethernet interface, which is then sent out to the radio network.
     *
     * The GW code is designed for Arduino 328p / 16MHz.  ATmega168 does not have enough memory to run this program.
     * 
     *
     * COMPILING WIZNET (W5100) ETHERNET MODULE
     * > Edit MyConfig.h in (libraries\MySensors\) to enable softspi (remove // before "#define SOFTSPI").
     *
     * COMPILING ENC28J60 ETHERNET MODULE
     * > Use Arduino IDE 1.5.7 (or later) 
     * > Disable DEBUG in Sensor.h before compiling this sketch. Othervise the sketch will probably not fit in program space when downloading. 
     * > Remove Ethernet.h include below and include UIPEthernet.h 
     * > Remove DigitalIO include 
     * Note that I had to disable UDP and DHCP support in uipethernet-conf.h to reduce space. (which means you have to choose a static IP for that module)
     *
     * VERA CONFIGURATION:
     * Enter "ip-number:port" in the ip-field of the Arduino GW device. This will temporarily override any serial configuration for the Vera plugin. 
     * E.g. If you want to use the defualt values in this sketch enter: 192.168.178.66:5003
     *
     * LED purposes:
     * - To use the feature, uncomment WITH_LEDS_BLINKING in MyConfig.h
     * - RX (green) - blink fast on radio message recieved. In inclusion mode will blink fast only on presentation recieved
     * - TX (yellow) - blink fast on radio message transmitted. In inclusion mode will blink slowly
     * - ERR (red) - fast blink on error during transmission error or recieve crc error  
     * 
     * See http://www.mysensors.org/build/ethernet_gateway for wiring instructions.
     *
     */
    #define NO_PORTB_PINCHANGES 
    
    #include <DigitalIO.h>     // This include can be removed when using UIPEthernet module  
    #include <SPI.h>  
    
    #include <MySigningNone.h>
    #include <MyTransportRFM69.h>
    #include <MyTransportNRF24.h>
    #include <MyHwATMega328.h>
    #include <MySigningAtsha204Soft.h>
    #include <MySigningAtsha204.h>
    
    #include <MyParserSerial.h>  
    #include <MySensor.h>  
    #include <stdarg.h>
    #include <PinChangeInt.h>
    #include "GatewayUtil.h"
    
    
    // Use this if you have attached a Ethernet ENC28J60 shields  
    // #include <UIPEthernet.h>  
    
    // Use this for WizNET W5100 module and Arduino Ethernet Shield 
    #include <Ethernet.h>   
    
    
    #define INCLUSION_MODE_TIME 1 // Number of minutes inclusion mode is enabled
    #define INCLUSION_MODE_PIN  3 // Digital pin used for inclusion mode button
    
    #define RADIO_CE_PIN        3  // radio chip enable
    #define RADIO_SPI_SS_PIN    8  // radio SPI serial select
    
    #define RADIO_ERROR_LED_PIN 7  // Error led pin
    #define RADIO_RX_LED_PIN    6  // Receive led pin
    #define RADIO_TX_LED_PIN    9  // the PCB, on board LED
    
    
    // NRFRF24L01 radio driver (set low transmit power by default) 
    MyTransportNRF24 transport(RADIO_CE_PIN, RADIO_SPI_SS_PIN, RF24_PA_LEVEL_GW);  
    //MyTransportRFM69 transport;
    
    // Message signing driver (signer needed if MY_SIGNING_FEATURE is turned on in MyConfig.h)
    //MySigningNone signer;
    //MySigningAtsha204Soft signer;
    //MySigningAtsha204 signer;
    
    // Hardware profile 
    MyHwATMega328 hw;
    
    // Construct MySensors library (signer needed if MY_SIGNING_FEATURE is turned on in MyConfig.h)
    // To use LEDs blinking, uncomment WITH_LEDS_BLINKING in MyConfig.h
    #ifdef WITH_LEDS_BLINKING
    MySensor gw(transport, hw /*, signer*/, RADIO_RX_LED_PIN, RADIO_TX_LED_PIN, RADIO_ERROR_LED_PIN);
    #else
    MySensor gw(transport, hw /*, signer*/);
    #endif
    
    
    #define IP_PORT 5003        // The port you want to open 
    IPAddress myIp (192, 168, 2, 62);  // Configure your static ip-address here    COMPILE ERROR HERE? Use Arduino IDE 1.5.7 or later!
    
    // The MAC address can be anything you want but should be unique on your network.
    // Newer boards have a MAC address printed on the underside of the PCB, which you can (optionally) use.
    // Note that most of the Ardunio examples use  "DEAD BEEF FEED" for the MAC address.
    byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };  // DEAD BEEF FEED
    
    // a R/W server on the port
    EthernetServer server = EthernetServer(IP_PORT);
    // handle to open connection
    EthernetClient client = EthernetClient();
    
    char inputString[MAX_RECEIVE_LENGTH] = "";    // A string to hold incoming commands from serial/ethernet interface
    int inputPos = 0;
    bool sentReady = false;
    
    void output(const char *fmt, ... ) {
       va_list args;
       va_start (args, fmt );
       vsnprintf_P(serialBuffer, MAX_SEND_LENGTH, fmt, args);
       va_end (args);
       Serial.print(serialBuffer);
       server.write(serialBuffer);
    }
    
    void setup()  
    { 
      Ethernet.begin(mac, myIp);
    
      setupGateway(INCLUSION_MODE_PIN, INCLUSION_MODE_TIME, output);
    
      // Add interrupt for inclusion button to pin
      PCintPort::attachInterrupt(pinInclusion, startInclusionInterrupt, RISING);
    
      // give the Ethernet interface a second to initialize
      delay(1000);
    
      // Initialize gateway at maximum PA level, channel 70 and callback for write operations 
      gw.begin(incomingMessage, 0, true, 0);
    
      
      // start listening for clients
      server.begin();
    
    }
    
    
    void loop() {
      gw.process();  
      
      checkButtonTriggeredInclusion();
      checkInclusionFinished();
      
      // if an incoming client connects, there will be
      // bytes available to read via the client object
      EthernetClient newclient = server.available();
      // if a new client connects make sure to dispose any previous existing sockets
      if (newclient) {
          if (client != newclient) {
           client.stop();
           client = newclient;
           output(PSTR("0;0;%d;0;%d;Gateway startup complete.\n"),  C_INTERNAL, I_GATEWAY_READY);
         }
       }
            
       if (client) {
         if (!client.connected()) {
           client.stop();
         } else if (client.available()) { 
           // read the bytes incoming from the client
           char inChar = client.read();
           if (inputPos<MAX_RECEIVE_LENGTH-1) { 
             // if newline then command is complete
             if (inChar == '\n') {  
               Serial.println("Finished");
                // a command was issued by the client
                // we will now try to send it to the actuator
                inputString[inputPos] = 0;
          
                // echo the string to the serial port
                Serial.print(inputString);
          
                parseAndSend(gw, inputString);
          
                // clear the string:
                inputPos = 0;
             } else {  
               // add it to the inputString:
               inputString[inputPos] = inChar;
               inputPos++;
             }
          } else {
             // Incoming message too long. Throw away 
             inputPos = 0;
          }
        }
      }
    }
    
    

    Sensor:
    Arduino Nano
    NRF24L01+ (Added 4.7u Decoupling Capacitor)
    Dallas Waterproof Temperature Sensor
    DHT II (temp/humidity)
    AC/DC Converter - https://www.itead.cc/power/ac-dc-power-module-5v-700ma-v2.html
    Sketch:

    #include <SPI.h>
    #include <MySensor.h>  
    #include <DHT.h>
    #include <DallasTemperature.h>
    #include <OneWire.h>
    
    #define CHILD_ID_HUM 1
    #define CHILD_ID_TEMP 2
    #define CHILD_ID_HTTEMP 3
    #define HUMIDITY_SENSOR_DIGITAL_PIN 3
    //Waterproof Sensor addition
    #define ONE_WIRE_BUS 4 //Pin where waterproof temp sensor is connected
    #define MAX_ATTACHED_DS18B20 16
    unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds)
    OneWire oneWire(ONE_WIRE_BUS);
    DallasTemperature sensors(&oneWire);
    
    MySensor gw;
    DHT dht;
    float lastTemperature[MAX_ATTACHED_DS18B20];
    int numSensors=0;
    boolean receivedConfig = false;
    float lastTemp;
    float lastHum;
    boolean metric = false; 
    MyMessage msgHum(CHILD_ID_HUM, V_HUM);
    MyMessage msgHumLCD(CHILD_ID_HUM, V_HUM);
    MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
    MyMessage msgTempLCD(CHILD_ID_TEMP, V_TEMP);
    MyMessage msgHTTemp(CHILD_ID_HTTEMP, V_TEMP);
    MyMessage msgHTTempLCD(CHILD_ID_HTTEMP, V_TEMP);
    
    void setup()  
    { 
      // Startup OneWire
      sensors.begin();
    
      gw.begin();
      dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN); 
      //Send Child Sensors to node 11
      msgHumLCD.setDestination(11);
      msgTempLCD.setDestination(11);
      msgHTTempLCD.setDestination(11);
    
      // Send the Sketch Version Information to the Gateway
      gw.sendSketchInfo("Hot Tub Monitor", "2.4");
    
      // Fetch the number of attached temperature sensors
      numSensors = sensors.getDeviceCount();
    
      // Present all sensors to controller
      for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) {
        gw.present(i, S_TEMP);
      }
    
      // Register all sensors to gw (they will be created as child devices)
      gw.present(CHILD_ID_HUM, S_HUM);
      gw.present(CHILD_ID_TEMP, S_TEMP);
    
      metric = gw.getConfig().isMetric;
    }
    
    void loop()      
    {  
      // Process incoming messages (like config from server)
      gw.process();
    
      //Fetch temperatures from Dallas sensors
      sensors.requestTemperatures();
    
      // Red temperatures and send them to the controller
      for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) {
    
        // Fetch and round temperature to one decimal
        float temperature = static_cast<float>(static_cast<int>((sensors.getTempFByIndex(i)) * 10.)) / 10.;
    
        //Only send data if temperature has changed and no error
        if (lastTemperature[i] != temperature && temperature != -127.00) {
    
          // Send in the new temperature
          delay(100);
          gw.send(msgHTTemp.setSensor(i).set(temperature,1));
          gw.send(msgHTTempLCD.set(static_cast<int>(temperature)));
          Serial.print("T2: ");
          Serial.println(temperature);
          lastTemperature[i]=temperature;
        }
      }
    
      delay(dht.getMinimumSamplingPeriod());
    
      //float temperature = dht.getTemperature();
      float temperature = dht.getTemperature()*9/5 + 32;
      if (isnan(temperature)) {
        Serial.println("Failed reading temperature from DHT");
      } 
      else if (temperature != lastTemp) {
        lastTemp = temperature;
        if (!metric) {
          //temperature = dht.toFahrenheit(temperature);
          temperature = dht.getTemperature()*9/5 + 32;
        }
        delay(100);
        gw.send(msgTemp.set(temperature, 1));
        gw.send(msgTempLCD.set(static_cast<int>(temperature)));
        Serial.print("T: ");
        Serial.println(temperature);
      }
    
      float humidity = dht.getHumidity();
      if (isnan(humidity)) {
        Serial.println("Failed reading humidity from DHT");
      } 
      else if (humidity != lastHum) {
        lastHum = humidity;
        delay(100);
        gw.send(msgHum.set(humidity, 1));
        gw.send(msgHumLCD.set(static_cast<int>(humidity)));
        Serial.print("H: ");
        Serial.println(humidity);
      }
    
      gw.sleep(SLEEP_TIME); //sleep a bit
    }
    

    Debug Log from Sensor:

    send: 1-1-0-0 s=255,c=0,t=17,pt=0,l=5,sg=0,st=fail:1.5.1
    send: 1-1-0-0 s=255,c=3,t=6,pt=1,l=1,sg=0,st=fail:0
    sensor started, id=1, parent=0, distance=1
    send: 1-1-0-0 s=255,c=3,t=11,pt=0,l=15,sg=0,st=fail:Hot Tub Monitor
    send: 1-1-0-0 s=255,c=3,t=12,pt=0,l=3,sg=0,st=fail:2.4
    send: 1-1-0-0 s=0,c=0,t=6,pt=0,l=0,sg=0,st=fail:
    send: 1-1-0-0 s=1,c=0,t=7,pt=0,l=0,sg=0,st=fail:
    find parent
    send: 1-1-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,st=bc:
    send: 1-1-0-0 s=2,c=0,t=6,pt=0,l=0,sg=0,st=fail:
    send: 1-1-0-0 s=0,c=1,t=0,pt=7,l=5,sg=0,st=fail:96.1
    send: 1-1-0-11 s=3,c=1,t=0,pt=2,l=2,sg=0,st=fail:96
    T2: 96.10
    send: 1-1-0-0 s=2,c=1,t=0,pt=7,l=5,sg=0,st=fail:71.6
    send: 1-1-0-11 s=2,c=1,t=0,pt=2,l=2,sg=0,st=fail:71
    T: 71.60
    send: 1-1-0-0 s=1,c=1,t=1,pt=7,l=5,sg=0,st=fail:39.0
    find parent
    send: 1-1-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,st=bc:
    send: 1-1-0-11 s=1,c=1,t=1,pt=2,l=2,sg=0,st=fail:39
    H: 39.00
    
    

    I have changed the wireless channel to 120, this didn't make any difference. I have also increased the power levels in myconfig.h to the following:

    #define RF24_PA_LEVEL 	   RF24_PA_MAX
    #define RF24_PA_LEVEL_GW   RF24_PA_MAX
    

    Didn't help so I then changed them to:

    #define RF24_PA_LEVEL 	   RF24_PA_HIGH
    #define RF24_PA_LEVEL_GW   RF24_PA_HIGH
    

    At this point I am not sure what to try. The sensor is inside of my Hot Tub Cabinet, doesn't have any metal around it but the signal does need to go around or through the 400 gallons of water.



  • Since no one has posted anything in the form of suggestions. I am going to order a NRF24L01+PA+LNA for my gateway and see if it helps. I built a simple temp/humidity sensor from the examples and have it directly 1 floor above the gateway and it isn't being picked up by the gateway either. The power supply going to my iBoard gateway is a 9V 1000ma wall wart, I believe this has plenty of power to run the Ardunio, Ethernet, and the radio. I have also switched the 4.7uf capacitor for a 47uf capacitor without luck either.


  • Hardware Contributor

    As you said, you tried the cap but for me its usually a power problem.
    Sometimes it is the sensor connected that draws to much power or makes the radio behave like this.
    Also sometimes its a bad radio.

    I would try to hook up the radio and arduino only (no sensors) and connect it to a different power supply and see if that makes any differnce.


  • Admin

    From what I read, 2.4Ghz travels extremely bad through water.



  • So my only options are a lp radio with an extension cable /antenna outside the hot tub cabinet or possibly the rm69 radio correct?

    Would it be possible to hard wire the sensor via ether net to the mysen sort network?



  • @cleight said:

    So my only options are a lp radio with an extension cable /antenna outside the hot tub cabinet or possibly the rm69 radio correct?

    Would it be possible to hard wire the sensor via ether net to the mysen sort network?

    Do you know what the converter on your board delivers? The 700mA from your wall wart may be fine but maybe the 9 to 3.3v converter on the board don't deliver enough current?
    Any signal will populate bad through water but normally it would "find" a way around that by reflections etc.



  • I recieved my NRF24L01+PA+LNA yesterday in the mail. I installed this on my gateway and still the range is exactly how it was to my sensors. I have built another simple temp/humidity sensor that is only 10' from the gateway and still cannot communicate to the gateway. I still have RF24_PA_MAX for both the sensors and the gateway and nothing.

    I am now at the point of wondering if I have a bad iBoard (gateway) that is causing these issues. Any more insight before I order another iBoard for a gateway?

    Also if I wanted to temporarily change from an ethernet gateway to a serial/usb gateway with Vera what all would be involved?



  • Good news! I was able to get everything working finally! Here it must of been an issue with my gateway sketch along with changing power settings on the gateway to RF24_PA_LOW. my only issue now with my gateway is Vera shows it constantly in inclusion mode, I believe it has something to do with my sketch, I don't have an inclusion button on my iBoard Gateway so I changed the PIN in the sketch to a fictitious pin but that seems to have just compounded the issue, if anyone can point me in the right direction on that front it would be much appreciated.

    /**
     * The MySensors Arduino library handles the wireless radio link and protocol
     * between your home built sensors/actuators and HA controller of choice.
     * The sensors forms a self healing radio network with optional repeaters. Each
     * repeater and gateway builds a routing tables in EEPROM which keeps track of the
     * network topology allowing messages to be routed to nodes.
     *
     * Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
     * Copyright (C) 2013-2015 Sensnology AB
     * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
     *
     * Documentation: http://www.mysensors.org
     * Support Forum: http://forum.mysensors.org
     *
     * This program is free software; you can redistribute it and/or
     * modify it under the terms of the GNU General Public License
     * version 2 as published by the Free Software Foundation.
     *
     *******************************
     *
     * REVISION HISTORY
     * Version 1.0 - Henrik EKblad
     * Contribution by a-lurker and Anticimex, 
     * Contribution by Norbert Truchsess <norbert.truchsess@t-online.de>
     *
     * 
     * DESCRIPTION
     * The EthernetGateway sends data received from sensors to the ethernet link. 
     * The gateway also accepts input on ethernet interface, which is then sent out to the radio network.
     *
     * The GW code is designed for Arduino 328p / 16MHz.  ATmega168 does not have enough memory to run this program.
     * 
     *
     * COMPILING WIZNET (W5100) ETHERNET MODULE
     * > Edit MyConfig.h in (libraries\MySensors\) to enable softspi (remove // before "#define SOFTSPI").
     *
     * COMPILING ENC28J60 ETHERNET MODULE
     * > Use Arduino IDE 1.5.7 (or later) 
     * > Disable DEBUG in Sensor.h before compiling this sketch. Othervise the sketch will probably not fit in program space when downloading. 
     * > Remove Ethernet.h include below and include UIPEthernet.h 
     * > Remove DigitalIO include 
     * Note that I had to disable UDP and DHCP support in uipethernet-conf.h to reduce space. (which means you have to choose a static IP for that module)
     *
     * VERA CONFIGURATION:
     * Enter "ip-number:port" in the ip-field of the Arduino GW device. This will temporarily override any serial configuration for the Vera plugin. 
     * E.g. If you want to use the defualt values in this sketch enter: 192.168.178.66:5003
     *
     * LED purposes:
     * - To use the feature, uncomment WITH_LEDS_BLINKING in MyConfig.h
     * - RX (green) - blink fast on radio message recieved. In inclusion mode will blink fast only on presentation recieved
     * - TX (yellow) - blink fast on radio message transmitted. In inclusion mode will blink slowly
     * - ERR (red) - fast blink on error during transmission error or recieve crc error  
     * 
     * See http://www.mysensors.org/build/ethernet_gateway for wiring instructions.
     *
     */
    #define NO_PORTB_PINCHANGES 
    
    #include <DigitalIO.h>     // This include can be removed when using UIPEthernet module  
    #include <SPI.h>  
    
    #include <MySigningNone.h>
    #include <MyTransportRFM69.h>
    #include <MyTransportNRF24.h>
    #include <MyHwATMega328.h>
    #include <MySigningAtsha204Soft.h>
    #include <MySigningAtsha204.h>
    
    #include <MyParserSerial.h>  
    #include <MySensor.h>  
    #include <stdarg.h>
    #include <PinChangeInt.h>
    #include "GatewayUtil.h"
    
    
    // Use this if you have attached a Ethernet ENC28J60 shields  
    // #include <UIPEthernet.h>  
    
    // Use this for WizNET W5100 module and Arduino Ethernet Shield 
    #include <Ethernet.h>   
    
    
    #define INCLUSION_MODE_TIME 1 // Number of minutes inclusion mode is enabled
    #define INCLUSION_MODE_PIN  14 // Digital pin used for inclusion mode button
    
    #define RADIO_CE_PIN        3  // radio chip enable
    #define RADIO_SPI_SS_PIN    8  // radio SPI serial select
    
    #define RADIO_ERROR_LED_PIN 7  // Error led pin
    #define RADIO_RX_LED_PIN    6  // Receive led pin
    #define RADIO_TX_LED_PIN    9  // the PCB, on board LED
    
    
    // NRFRF24L01 radio driver (set low transmit power by default) 
    MyTransportNRF24 transport(RADIO_CE_PIN, RADIO_SPI_SS_PIN, RF24_PA_LEVEL_GW);  
    //MyTransportRFM69 transport;
    
    // Message signing driver (signer needed if MY_SIGNING_FEATURE is turned on in MyConfig.h)
    //MySigningNone signer;
    //MySigningAtsha204Soft signer;
    //MySigningAtsha204 signer;
    
    // Hardware profile 
    MyHwATMega328 hw;
    
    // Construct MySensors library (signer needed if MY_SIGNING_FEATURE is turned on in MyConfig.h)
    // To use LEDs blinking, uncomment WITH_LEDS_BLINKING in MyConfig.h
    #ifdef WITH_LEDS_BLINKING
    MySensor gw(transport, hw /*, signer*/, RADIO_RX_LED_PIN, RADIO_TX_LED_PIN, RADIO_ERROR_LED_PIN);
    #else
    MySensor gw(transport, hw /*, signer*/);
    #endif
    
    
    #define IP_PORT 5003        // The port you want to open 
    IPAddress myIp (192, 168, 2, 62);  // Configure your static ip-address here    COMPILE ERROR HERE? Use Arduino IDE 1.5.7 or later!
    
    // The MAC address can be anything you want but should be unique on your network.
    // Newer boards have a MAC address printed on the underside of the PCB, which you can (optionally) use.
    // Note that most of the Ardunio examples use  "DEAD BEEF FEED" for the MAC address.
    byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };  // DEAD BEEF FEED
    
    // a R/W server on the port
    EthernetServer server = EthernetServer(IP_PORT);
    // handle to open connection
    EthernetClient client = EthernetClient();
    
    char inputString[MAX_RECEIVE_LENGTH] = "";    // A string to hold incoming commands from serial/ethernet interface
    int inputPos = 0;
    bool sentReady = false;
    
    void output(const char *fmt, ... ) {
       va_list args;
       va_start (args, fmt );
       vsnprintf_P(serialBuffer, MAX_SEND_LENGTH, fmt, args);
       va_end (args);
       Serial.print(serialBuffer);
       server.write(serialBuffer);
    }
    
    void setup()  
    { 
      Ethernet.begin(mac, myIp);
    
      setupGateway(INCLUSION_MODE_PIN, INCLUSION_MODE_TIME, output);
    
      // Add interrupt for inclusion button to pin
      PCintPort::attachInterrupt(pinInclusion, startInclusionInterrupt, RISING);
    
      // give the Ethernet interface a second to initialize
      delay(1000);
    
      // Initialize gateway at maximum PA level, channel 70 and callback for write operations 
      gw.begin(incomingMessage, 0, true, 0);
    
      
      // start listening for clients
      server.begin();
    
    }
    
    
    void loop() {
      gw.process();  
      
      checkButtonTriggeredInclusion();
      checkInclusionFinished();
      
      // if an incoming client connects, there will be
      // bytes available to read via the client object
      EthernetClient newclient = server.available();
      // if a new client connects make sure to dispose any previous existing sockets
      if (newclient) {
          if (client != newclient) {
           client.stop();
           client = newclient;
           output(PSTR("0;0;%d;0;%d;Gateway startup complete.\n"),  C_INTERNAL, I_GATEWAY_READY);
         }
       }
            
       if (client) {
         if (!client.connected()) {
           client.stop();
         } else if (client.available()) { 
           // read the bytes incoming from the client
           char inChar = client.read();
           if (inputPos<MAX_RECEIVE_LENGTH-1) { 
             // if newline then command is complete
             if (inChar == '\n') {  
               Serial.println("Finished");
                // a command was issued by the client
                // we will now try to send it to the actuator
                inputString[inputPos] = 0;
          
                // echo the string to the serial port
                Serial.print(inputString);
          
                parseAndSend(gw, inputString);
          
                // clear the string:
                inputPos = 0;
             } else {  
               // add it to the inputString:
               inputString[inputPos] = inChar;
               inputPos++;
             }
          } else {
             // Incoming message too long. Throw away 
             inputPos = 0;
          }
        }
      }
    }
    


  • @cleight Did you use the hardware modification for your iBoard or go the software route? FYI - Pin 14 isn't fictitious, it is pin A0.



  • Hardware mod


Log in to reply
 

Suggested Topics

  • 3
  • 5
  • 1
  • 8
  • 2

0
Online

11.4k
Users

11.1k
Topics

112.7k
Posts