Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. Troubleshooting
  3. Serial gateway with several sensors connected to it

Serial gateway with several sensors connected to it

Scheduled Pinned Locked Moved Troubleshooting
26 Posts 5 Posters 7.7k Views 5 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • skatunS skatun

    @TimO
    I will look into it, however first I need to get the gateway up running.

    So I am struggling to see how locally attached sensors work. I guess (reading several forum entry) that gw object is not needed. What is this inclusion mode? Is that part of the code needed?

    However I can not get my code to compile:

    
    #include <SPI.h>
    #include <MySensor.h>  
    
    
    // Enable debug prints to serial monitor
    #define MY_DEBUG 
    
    
    // Enable serial gateway
    #define MY_GATEWAY_SERIAL
    
    // Flash leds on rx/tx/err
    #define MY_LEDS_BLINKING_FEATURE
    // Set blinking period
    #define MY_DEFAULT_LED_BLINK_PERIOD 300
    
    // Enable inclusion mode
    #define MY_INCLUSION_MODE_FEATURE
    // Enable Inclusion mode button on gateway
    #define MY_INCLUSION_BUTTON_FEATURE
    
    // Set inclusion mode duration (in seconds)
    #define MY_INCLUSION_MODE_DURATION 60 
    // Digital pin used for inclusion mode button
    #define MY_INCLUSION_MODE_BUTTON_PIN  3 
    
    
    #define DIGITAL_INPUT_SENSOR 3  // The digital input you attached your light sensor.  (Only 2 and 3 generates interrupt!)
    #define PULSE_FACTOR 1000       // Nummber of blinks per KWH of your meeter
    #define SLEEP_MODE false        // Watt-value can only be reported when sleep mode is false.
    #define MAX_WATT 10000          // Max watt value to report. This filetrs outliers.
    #define INTERRUPT DIGITAL_INPUT_SENSOR-2 // Usually the interrupt = pin -2 (on uno/nano anyway)
    #define CHILD_ID 9              // Id of the sensor child
    unsigned long SEND_FREQUENCY = 20000; // Minimum time between send (in milliseconds). We don't wnat to spam the gateway.
    MySensor gw;
    double ppwh = ((double)PULSE_FACTOR)/1000; // Pulses per watt hour
    boolean pcReceived = false;
    volatile unsigned long pulseCount = 0;   
    volatile unsigned long lastBlink = 0;
    volatile unsigned long watt = 0;
    unsigned long oldPulseCount = 0;   
    unsigned long oldWatt = 0;
    double oldKwh;
    unsigned long lastSend;
    MyMessage wattMsg(CHILD_ID,V_WATT);
    MyMessage kwhMsg(CHILD_ID,V_KWH);
    MyMessage pcMsg(CHILD_ID,V_VAR1);
    
    
    void setup()  
    {  
        attachInterrupt(INTERRUPT, onPulse, RISING);
        lastSend=millis();
    }
    
    
    void presentation() {
      // Present locally attached sensors here
      
        // Register this device as power sensor
        gw.present(CHILD_ID, S_POWER,"Energy Meter");
    }
    
    void loop()     
    { 
      gw.process();
      unsigned long now = millis();
      // Only send values at a maximum frequency or woken up from sleep
      bool sendTime = now - lastSend > SEND_FREQUENCY;
      if (pcReceived && (SLEEP_MODE || sendTime)) {
        // New watt value has been calculated  
        if (!SLEEP_MODE && watt != oldWatt) {
          // Check that we dont get unresonable large watt value. 
          // could hapen when long wraps or false interrupt triggered
          if (watt<((unsigned long)MAX_WATT)) {
            gw.send(wattMsg.set(watt));  // Send watt value to gw 
          }  
          //Serial.print("Watt:");
          //Serial.println(watt);
          oldWatt = watt;
        }
      
        // Pulse cout has changed
        if (pulseCount != oldPulseCount) {
          //gw.send(pcMsg.set(pulseCount));  // Send pulse count value to gw 
          double kwh = ((double)pulseCount/((double)PULSE_FACTOR));     
          oldPulseCount = pulseCount;
          if (kwh != oldKwh) {
            gw.send(kwhMsg.set(kwh, 4));  // Send kwh value to gw 
            oldKwh = kwh;
          }
        }    
        lastSend = now;
      } else if (sendTime && !pcReceived) {
        // No count received. Try requesting it again
        request(CHILD_ID, V_VAR1);
        lastSend=now;
      }
      
      if (SLEEP_MODE) {
        sleep(SEND_FREQUENCY);
      }
      
    }
    
    void incomingMessage(const MyMessage &message) {
      if (message.type==V_VAR1) {  
        pulseCount = oldPulseCount = message.getLong();
        //Serial.print("Received last pulse count from gw:");
        //Serial.println(pulseCount);
        pcReceived = true;
      }
    }
    
    void onPulse()     
    { 
      if (!SLEEP_MODE) {
        unsigned long newBlink = micros();  
        unsigned long interval = newBlink-lastBlink;
        if (interval<10000L) { // Sometimes we get interrupt on RISING
          return;
        }
        watt = (3600000000.0 /interval) / ppwh;
        lastBlink = newBlink;
      } 
      pulseCount++;
    }
    
    AWIA Offline
    AWIA Offline
    AWI
    Hero Member
    wrote on last edited by
    #12

    @skatun it looks like you are mixing the development version 2.0 and master branch 1.5 syntax. In development the "class" setup is removed and therefore for "gw." is not used anymore.

    Most of the examples use the gw. Structure though. Look at the samples in the development branch as you will probably want/need the new functionality

    skatunS 1 Reply Last reply
    0
    • AWIA AWI

      @skatun it looks like you are mixing the development version 2.0 and master branch 1.5 syntax. In development the "class" setup is removed and therefore for "gw." is not used anymore.

      Most of the examples use the gw. Structure though. Look at the samples in the development branch as you will probably want/need the new functionality

      skatunS Offline
      skatunS Offline
      skatun
      wrote on last edited by
      #13

      @AWI
      So I copied ower evrything in the library folder of the development branch. When i then try to compile the serial gateway i get this error:

      Arduino: 1.6.7 (Windows 7), Board: "NodeMCU 1.0 (ESP-12E Module), 80 MHz, Serial, 115200, 4M (3M SPIFFS)"
      
      In file included from C:\Program Files (x86)\Arduino\libraries\MySensors\examples\SerialGateway\SerialGateway.ino:50:0:
      
      C:\Program Files (x86)\Arduino\libraries\MySensors/MySensor.h:285:4: error: #error No forward link or gateway feature activated. This means nowhere to send messages! Pretty pointless.
      
         #error No forward link or gateway feature activated. This means nowhere to send messages! Pretty pointless.
      
          ^
      
      In file included from C:\Program Files (x86)\Arduino\libraries\MySensors\examples\SerialGateway\SerialGateway.ino:52:0:
      
      
      C:\Program Files (x86)\Arduino\libraries\PinChangeInt/PinChangeInt.h:103:19: fatal error: new.h: No such file or directory
      
         #include <new.h>
      
                         ^
      
      compilation terminated.
      
      exit status 1
      Error compiling.
      
        This report would have more information with
        "Show verbose output during compilation"
        enabled in File > Preferences.
      
      AWIA 1 Reply Last reply
      0
      • skatunS skatun

        @AWI
        So I copied ower evrything in the library folder of the development branch. When i then try to compile the serial gateway i get this error:

        Arduino: 1.6.7 (Windows 7), Board: "NodeMCU 1.0 (ESP-12E Module), 80 MHz, Serial, 115200, 4M (3M SPIFFS)"
        
        In file included from C:\Program Files (x86)\Arduino\libraries\MySensors\examples\SerialGateway\SerialGateway.ino:50:0:
        
        C:\Program Files (x86)\Arduino\libraries\MySensors/MySensor.h:285:4: error: #error No forward link or gateway feature activated. This means nowhere to send messages! Pretty pointless.
        
           #error No forward link or gateway feature activated. This means nowhere to send messages! Pretty pointless.
        
            ^
        
        In file included from C:\Program Files (x86)\Arduino\libraries\MySensors\examples\SerialGateway\SerialGateway.ino:52:0:
        
        
        C:\Program Files (x86)\Arduino\libraries\PinChangeInt/PinChangeInt.h:103:19: fatal error: new.h: No such file or directory
        
           #include <new.h>
        
                           ^
        
        compilation terminated.
        
        exit status 1
        Error compiling.
        
          This report would have more information with
          "Show verbose output during compilation"
          enabled in File > Preferences.
        
        AWIA Offline
        AWIA Offline
        AWI
        Hero Member
        wrote on last edited by
        #14

        @skatun It's hard to tell (for me ;-)) from the messages what is going wrong. Which Arduino are you programming for? Are you using the "GatewaySerial.ino" sketch from the development branch examples?

        skatunS 1 Reply Last reply
        0
        • AWIA AWI

          @skatun It's hard to tell (for me ;-)) from the messages what is going wrong. Which Arduino are you programming for? Are you using the "GatewaySerial.ino" sketch from the development branch examples?

          skatunS Offline
          skatunS Offline
          skatun
          wrote on last edited by
          #15

          @AWI
          I just copied all the files in libraries and hardware in the development zip into c:\program files\Arduino\

          I am trying to get it to run on arduino due and yes I was trying the run the Serial gateway in Library\My Sensor\SerialGateway

          skatunS 1 Reply Last reply
          0
          • skatunS skatun

            @AWI
            I just copied all the files in libraries and hardware in the development zip into c:\program files\Arduino\

            I am trying to get it to run on arduino due and yes I was trying the run the Serial gateway in Library\My Sensor\SerialGateway

            skatunS Offline
            skatunS Offline
            skatun
            wrote on last edited by
            #16

            @AWI How do I Install the development branch correctly? Does it only work with nano 328?

            1 Reply Last reply
            0
            • sundberg84S Offline
              sundberg84S Offline
              sundberg84
              Hardware Contributor
              wrote on last edited by sundberg84
              #17

              Hi @skatun did you check this http://www.mysensors.org/about/arduino#installing-the-sensor-libraries ? You install it the same way but download it from https://github.com/mysensors/Arduino (press Download ZIP) and make sure its Branch: Development.

              Controller: Proxmox VM - Home Assistant
              MySensors GW: Arduino Uno - W5100 Ethernet, Gw Shield Nrf24l01+ 2,4Ghz
              MySensors GW: Arduino Uno - Gw Shield RFM69, 433mhz
              RFLink GW - Arduino Mega + RFLink Shield, 433mhz

              skatunS 1 Reply Last reply
              0
              • sundberg84S sundberg84

                Hi @skatun did you check this http://www.mysensors.org/about/arduino#installing-the-sensor-libraries ? You install it the same way but download it from https://github.com/mysensors/Arduino (press Download ZIP) and make sure its Branch: Development.

                skatunS Offline
                skatunS Offline
                skatun
                wrote on last edited by
                #18

                @sundberg84

                Well I tried to save it both here:
                C:\Program Files (x86)\Arduino\libraries\Mysensor
                C:\Program Files (x86)\Arduino\hardware\MySensors

                As well as here as described in your link:
                C:\Users\kim\Documents\Arduino

                But I get compile errors no matter where I try to compile serialgateway on due which I found in the C:\Program Files (x86)\Arduino\libraries\MySensors\examples\SerialGateway

                Cheers

                1 Reply Last reply
                0
                • sundberg84S Offline
                  sundberg84S Offline
                  sundberg84
                  Hardware Contributor
                  wrote on last edited by
                  #19

                  @skatun having the files in multiple folders isnt a good idea.
                  Maybe you should remove the IDE and all folders and start over?

                  Controller: Proxmox VM - Home Assistant
                  MySensors GW: Arduino Uno - W5100 Ethernet, Gw Shield Nrf24l01+ 2,4Ghz
                  MySensors GW: Arduino Uno - Gw Shield RFM69, 433mhz
                  RFLink GW - Arduino Mega + RFLink Shield, 433mhz

                  skatunS 1 Reply Last reply
                  0
                  • sundberg84S sundberg84

                    @skatun having the files in multiple folders isnt a good idea.
                    Maybe you should remove the IDE and all folders and start over?

                    skatunS Offline
                    skatunS Offline
                    skatun
                    wrote on last edited by
                    #20

                    @sundberg84
                    So the IDE by default get installed C:\Program Files (x86)\Arduino but the files folder get default set to this:

                    C:\Users\kim\Documents\Arduino

                    I guess arduino made it that way so that you can load examples from C:\Program Files (x86)\Arduino then mess around with them and save them here C:\Users\kim\Documents\Arduino

                    So I never had duplicate files, i tried both locations without sucsess. So which version of the IDE should I use? 1.6.7 is what I have now.

                    1 Reply Last reply
                    0
                    • sundberg84S Offline
                      sundberg84S Offline
                      sundberg84
                      Hardware Contributor
                      wrote on last edited by
                      #21

                      @skatun Dont know if there are any version conflicts at the moment.
                      I dont have the latest version.

                      Controller: Proxmox VM - Home Assistant
                      MySensors GW: Arduino Uno - W5100 Ethernet, Gw Shield Nrf24l01+ 2,4Ghz
                      MySensors GW: Arduino Uno - Gw Shield RFM69, 433mhz
                      RFLink GW - Arduino Mega + RFLink Shield, 433mhz

                      skatunS 1 Reply Last reply
                      0
                      • sundberg84S sundberg84

                        @skatun Dont know if there are any version conflicts at the moment.
                        I dont have the latest version.

                        skatunS Offline
                        skatunS Offline
                        skatun
                        wrote on last edited by
                        #22

                        @sundberg84
                        So which directory should i put the files in? BOth hardware and library?

                        1 Reply Last reply
                        0
                        • sundberg84S Offline
                          sundberg84S Offline
                          sundberg84
                          Hardware Contributor
                          wrote on last edited by
                          #23

                          I install the ide. download and extract mys to same path as ide. That's it.

                          Controller: Proxmox VM - Home Assistant
                          MySensors GW: Arduino Uno - W5100 Ethernet, Gw Shield Nrf24l01+ 2,4Ghz
                          MySensors GW: Arduino Uno - Gw Shield RFM69, 433mhz
                          RFLink GW - Arduino Mega + RFLink Shield, 433mhz

                          skatunS 1 Reply Last reply
                          0
                          • sundberg84S sundberg84

                            I install the ide. download and extract mys to same path as ide. That's it.

                            skatunS Offline
                            skatunS Offline
                            skatun
                            wrote on last edited by
                            #24

                            @sundberg84

                            I will then delete C:\Users\kim\Documents\Arduino which the ide creates.. Will upgrtade today, and let you know how it goes

                            barduinoB 1 Reply Last reply
                            0
                            • skatunS skatun

                              @sundberg84

                              I will then delete C:\Users\kim\Documents\Arduino which the ide creates.. Will upgrtade today, and let you know how it goes

                              barduinoB Offline
                              barduinoB Offline
                              barduino
                              wrote on last edited by
                              #25

                              @skatun

                              Default libraries included in the IDE

                              0_1459942591088_upload-a9ff62dc-42ba-4ef2-9f12-16091cd52ad0

                              User libraries

                              0_1459942680955_upload-c18bf0b4-2121-46ae-8fe3-d2441be6dedd

                              Its not uncommon to have compile issues when:

                              • The IDE is not restarted after uncompressing/copy file to the libraries

                              • When upgrading MySensors without deleting the old version first

                              I have Arduino IDE 1.6.4

                              Cheers

                              skatunS 1 Reply Last reply
                              1
                              • barduinoB barduino

                                @skatun

                                Default libraries included in the IDE

                                0_1459942591088_upload-a9ff62dc-42ba-4ef2-9f12-16091cd52ad0

                                User libraries

                                0_1459942680955_upload-c18bf0b4-2121-46ae-8fe3-d2441be6dedd

                                Its not uncommon to have compile issues when:

                                • The IDE is not restarted after uncompressing/copy file to the libraries

                                • When upgrading MySensors without deleting the old version first

                                I have Arduino IDE 1.6.4

                                Cheers

                                skatunS Offline
                                skatunS Offline
                                skatun
                                wrote on last edited by
                                #26

                                @barduino
                                Upgrading to Arduino 1.6.8 did the trick.
                                Thanks.

                                1 Reply Last reply
                                0
                                Reply
                                • Reply as topic
                                Log in to reply
                                • Oldest to Newest
                                • Newest to Oldest
                                • Most Votes


                                24

                                Online

                                11.7k

                                Users

                                11.2k

                                Topics

                                113.1k

                                Posts


                                Copyright 2025 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
                                • Login

                                • Don't have an account? Register

                                • Login or register to search.
                                • First post
                                  Last post
                                0
                                • MySensors
                                • OpenHardware.io
                                • Categories
                                • Recent
                                • Tags
                                • Popular