Navigation

    • Register
    • Login
    • OpenHardware.io
    • Categories
    • Recent
    • Tags
    • Popular
    1. Home
    2. patrick schaerer
    3. Posts
    • Profile
    • Following
    • Followers
    • Topics
    • Posts
    • Best
    • Groups

    Posts made by patrick schaerer

    • RE: irrigation controller arduino mega doesn't work anymore

      I found the problem ...
      due to a defective sensor (light meter) the arduino could not initialize correctly.
      I think that is why it was calling back setup()

      posted in Development
      patrick schaerer
      patrick schaerer
    • RE: irrigation controller arduino mega doesn't work anymore

      thank you for the link

      18743 MCO:PIM:NODE REG=1	Registration response received, registration status 1
      18746 MCO:BGN:STP	Callback setup()
      

      What is Registration status 1?
      Does Callback setup() reinitialize the node?

      posted in Development
      patrick schaerer
      patrick schaerer
    • irrigation controller arduino mega doesn't work anymore

      Arduino Mega Node not working anymore
      I have an arduino mega used for automated irrigation after a year of service the node is not responding anymore.
      The node runs on mysensor 2.1.1
      The serial monitor shows the following

      0 MCO:BGN:INIT NODE,CP=RNNNA--,VER=2.1.1
      3 TSM:INIT
      4 TSF:WUR:MS=0
      11 TSM:INIT:TSP OK
      13 TSF:SID:OK,ID=5
      15 TSM:FPAR
      51 TSF:MSG:SEND,5-5-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
      2058 !TSM:FPAR:NO REPLY
      2060 TSM:FPAR
      2096 TSF:MSG:SEND,5-5-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
      2910 TSF:MSG:READ,11-11-5,s=255,c=3,t=8,pt=1,l=1,sg=0:3
      2915 TSF:MSG:FPAR OK,ID=11,D=4
      4104 TSM:FPAR:OK
      4105 TSM:ID
      4106 TSM:ID:OK
      4108 TSM:UPL
      4113 TSF:MSG:SEND,5-5-11-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=OK:1
      6120 TSM:UPL
      6125 TSF:MSG:SEND,5-5-11-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=OK:1
      8132 TSM:UPL
      8137 TSF:MSG:SEND,5-5-11-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=OK:1
      8212 TSF:MSG:READ,0-11-5,s=255,c=3,t=25,pt=1,l=1,sg=0:4
      8217 TSF:MSG:PONG RECV,HP=4
      8219 TSM:UPL:OK
      8221 TSM:READY:ID=5,PAR=11,DIS=4
      8246 TSF:MSG:SEND,5-5-11-0,s=255,c=3,t=15,pt=6,l=2,sg=0,ft=0,st=OK:0100
      10255 TSF:MSG:SEND,5-5-11-0,s=255,c=0,t=17,pt=0,l=5,sg=0,ft=0,st=OK:2.1.1
      10297 !TSF:MSG:SEND,5-5-11-0,s=255,c=3,t=6,pt=1,l=1,sg=0,ft=0,st=NACK:11
      12307 TSF:MSG:SEND,5-5-11-0,s=255,c=3,t=11,pt=0,l=12,sg=0,ft=1,st=OK:Bewässerung
      12351 !TSF:MSG:SEND,5-5-11-0,s=255,c=3,t=12,pt=0,l=3,sg=0,ft=0,st=NACK:2.1
      12388 TSF:MSG:SEND,5-5-11-0,s=13,c=0,t=6,pt=0,l=0,sg=0,ft=1,st=OK:
      12396 TSF:MSG:SEND,5-5-11-0,s=14,c=0,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
      12437 !TSF:MSG:SEND,5-5-11-0,s=15,c=0,t=16,pt=0,l=0,sg=0,ft=0,st=NACK:
      12445 TSF:MSG:SEND,5-5-11-0,s=1,c=0,t=7,pt=0,l=0,sg=0,ft=1,st=OK:
      12465 TSF:MSG:SEND,5-5-11-0,s=9,c=0,t=3,pt=0,l=0,sg=0,ft=0,st=OK:
      12474 TSF:MSG:SEND,5-5-11-0,s=2,c=0,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
      12482 TSF:MSG:SEND,5-5-11-0,s=10,c=0,t=3,pt=0,l=0,sg=0,ft=0,st=OK:
      12492 TSF:MSG:SEND,5-5-11-0,s=3,c=0,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
      12533 !TSF:MSG:SEND,5-5-11-0,s=11,c=0,t=3,pt=0,l=0,sg=0,ft=0,st=NACK:
      12541 TSF:MSG:SEND,5-5-11-0,s=4,c=0,t=7,pt=0,l=0,sg=0,ft=1,st=OK:
      12582 !TSF:MSG:SEND,5-5-11-0,s=12,c=0,t=3,pt=0,l=0,sg=0,ft=0,st=NACK:
      12590 MCO:REG:REQ
      12614 TSF:MSG:SEND,5-5-11-0,s=255,c=3,t=26,pt=1,l=1,sg=0,ft=1,st=OK:2
      14625 TSF:MSG:SEND,5-5-11-0,s=255,c=3,t=26,pt=1,l=1,sg=0,ft=0,st=OK:2
      16635 TSF:MSG:SEND,5-5-11-0,s=255,c=3,t=26,pt=1,l=1,sg=0,ft=0,st=OK:2
      18647 TSF:MSG:SEND,5-5-11-0,s=255,c=3,t=26,pt=1,l=1,sg=0,ft=0,st=OK:2
      18738 TSF:MSG:READ,0-11-5,s=255,c=3,t=27,pt=1,l=1,sg=0:1
      18743 MCO:PIM:NODE REG=1
      18746 MCO:BGN:STP
      

      after MCO:BGN:STP nothing happens
      what does MCO:BGN:STP mean?
      greets
      patrick

      posted in Development
      patrick schaerer
      patrick schaerer
    • RE: SCT-013-030 Energy Meter

      I alread updated to MySensors 2.0

      This is the update code:

      I also edited the first post.

      /**
       * 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.
       *
       *******************************
       *
       * EnergyMeterSCT by Patrick Schaerer
       * This Sketch is a WattMeter used with a SCT-013-030 non invasive PowerMeter
       * see documentation for schematic
       * 
       * Special thanks to Surge, who optimized my code.
       * 
       * updated to mySensors Library 2.0
       */
      
      
      #define MY_RADIO_NRF24
      #define MY_REPEATER_FEATURE
      #define MY_DEBUG
      
      
      #include <SPI.h>
      #include <MySensors.h>  
      #include <EmonLib.h> 
       
      #define ANALOG_INPUT_SENSOR 1  // The digital input you attached your SCT sensor.  (Only 2 and 3 generates interrupt!)
      //#define INTERRUPT DIGITAL_INPUT_SENSOR-2 // Usually the interrupt = pin -2 (on uno/nano anyway)
      #define CHILD_ID 1              // Id of the sensor child
      
      EnergyMonitor emon1;
      
      MyMessage wattMsg(CHILD_ID,V_WATT);
      MyMessage kwhMsg(CHILD_ID,V_KWH);
      MyMessage msgKWH(CHILD_ID,V_VAR1);
      unsigned long SLEEP_TIME = 60000 - 3735; // sleep for 60 seconds (-4 seconds to calculate values)
      
      float wattsumme = 0;
      float kwh = 0;
      float wh = 0;
      int minuten = 0;  //vorher 61
      boolean KWH_received=false;
      
      //Humidity Sensor Code
      #include <DHT.h>  
      #define CHILD_ID_HUM 2
      #define CHILD_ID_TEMP 3
      #define HUMIDITY_SENSOR_DIGITAL_PIN 2
      DHT dht;
      float lastTemp;
      float lastHum;
      boolean metric = true; 
      MyMessage msgHum(CHILD_ID_HUM, V_HUM);
      MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
      
      //End of Humidity Sensor Code
      
      
      void setup()  
      {  
        //energy clamp code
        //gw.begin(incomingMessage, AUTO, true,0); 
        
        Serial.begin(115200);
        emon1.current(ANALOG_INPUT_SENSOR, 30);             // Current: input pin, calibration.
      
        
        double Irms = emon1.calcIrms(1480);  // initial boot to charge up capacitor (no reading is taken) - testing
        request(CHILD_ID,V_VAR1);
        //end of energy clamp code
      
      //Humidity Sensor Code
        dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN);   
        metric = getConfig().isMetric;
        //End of Humidity Sensor Code 
      }
      
      void presentation() {
        // Send the sketch version information to the gateway and Controller
        // Register this device as power sensor
      sendSketchInfo("Energy Meter SCT013", "2.0");
      present(CHILD_ID, S_POWER);
      present(CHILD_ID_HUM, S_HUM);
      present(CHILD_ID_TEMP, S_TEMP);
      
      }
      void loop()     
      { 
        
        //process();
      
        //KWH reveived check
        if (!KWH_received) request(CHILD_ID,V_VAR1);
        
        // power used each minute
        if (minuten < 60) {
          double Irms = emon1.calcIrms(1480);  // Calculate Irms only
          if (Irms < 0.3) Irms = 0;
          long watt = Irms*240.0; // default was 230 but our local voltage is about 240
          wattsumme = wattsumme+watt;
          minuten++;
          send(wattMsg.set(watt));  // Send watt value to gw
          
          Serial.print(watt);         // Apparent power
          Serial.print("W I= ");
          Serial.println(Irms);          // Irms   
        }
        // end power used each minute
        
        // hours KW reading
        if (minuten >= 60) {
          wh = wh + wattsumme/60;
          kwh = wh/1000;
          send(kwhMsg.set(kwh, 3)); // Send kwh value to gw 
          send(msgKWH.set(kwh, 3)); // Send kwh value to gw
          wattsumme = 0;
          minuten = 0;
        }
      // end of hourly KW reading
          
      // Humidity Sensor Code
       if (minuten == 15 || minuten == 30 || minuten == 45|| minuten == 60) {
          float temperature = dht.getTemperature();
          if (isnan(temperature)) {
            Serial.println("Failed reading temperature from DHT");
          } else if (temperature != lastTemp) {
            lastTemp = temperature;
          if (!metric) {
            temperature = dht.toFahrenheit(temperature);
          }
          send(msgTemp.set(temperature, 1));
          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;
            send(msgHum.set(humidity, 1));
            Serial.print("H: ");
            Serial.println(humidity);
        }
       }
      
       //End of Humidity Sensor Code
       wait(SLEEP_TIME);
      }
      
      void receive(const MyMessage &message) {
        if (message.type==V_VAR1) {  
          kwh = message.getFloat();
          wh = kwh*1000;
          Serial.print("Received last KWH from gw:");
          Serial.println(kwh);
          //send(kwhMsg.set(kwh, 3)); // Send kwh value to gw 
          KWH_received = true;
        }
      }
          
      
      
      posted in My Project
      patrick schaerer
      patrick schaerer
    • RE: openHAB 2.0 binding

      @TimO said:

      @bentrik said:

      I managed to find an addons directory in /usr/share/openhab2/addons, but I can´t find a way to copy the .jar file there, as I get permission denied both through WinSCP in sudo mode and terminal ssh. The folder has permission 0775.

      That is the correct directory if you installed OH2 via .deb. Seems like you are using a user in WinSCP that is not allowed to write to the directory above. To circumvent this:

      1. Copy the binding jar to /tmp.
      2. Login via ssh and execute:
      sudo cp /tmp/org.openhab.binding.mysensors-2.0.0-SNAPSHOT.jar /usr/share/openhab2/addons/
      

      and

      sudo chmod openhab.openhab /usr/share/openhab2/addons/org.openhab.binding.mysensors-2.0.0-SNAPSHOT.jar
      

      OH2 is started/stopped/restarted with

      service openhab2 start/stop/restart
      

      To log into the karaf console do:

      ssh openhab@localhost -p 8101
      

      Password is: habopen

      Follow the guide/wiki from:

      In the console enter feature:install openhab-transport-serial
      

      I have installed openhab with the openhabian image. I could start the mysensors gateway too.
      I followed the github-openhab2 installation instructions.
      To this point

      In the console enter feature:install openhab-transport-serial
      

      I read a lot of posts on this thread but on get this error:

      openhab> install openhab-transport-serial
      Bundle IDs:
      Error executing command: Error installing bundles:
      	Unable to install bundle openhab-transport-serial
      

      the chmod line posted above doesn't work neither. chmod does not accept openhab.openhab

      I dont have any clue how to install the binding for openhab2 ... why isn't that possible from paperui 😞

      posted in OpenHAB
      patrick schaerer
      patrick schaerer
    • RE: openhabian mySensors setup
      sudo apt-get install g++
      

      then I could do "make"

      posted in OpenHAB
      patrick schaerer
      patrick schaerer
    • RE: openhabian mySensors setup

      ok thanks
      i'll try

      posted in OpenHAB
      patrick schaerer
      patrick schaerer
    • openhabian mySensors setup

      Make command doesn't work on openhabian image.

      I installed openhab with the openhabian image and it works.
      I did the following ...

      [15:20:07] pi@openHABianPi:~$ git clone https://github.com/mysensors/MySensors.git
      Cloning into 'MySensors'...
      remote: Counting objects: 13297, done.
      remote: Total 13297 (delta 0), reused 0 (delta 0), pack-reused 13296
      Receiving objects: 100% (13297/13297), 9.34 MiB | 3.35 MiB/s, done.
      Resolving deltas: 100% (7989/7989), done.
      Checking connectivity... done.
      [15:20:54] pi@openHABianPi:~$ cd MySensors
      [15:21:01] pi@openHABianPi:~/MySensors$ ./configure --help
      15:21:10] pi@openHABianPi:~/MySensors$ ./configure --my-transport=nrf24 --my-rf24-irq-pin=15
      [SECTION] Detecting target machine.
      [OK] machine detected: SoC=BCM2836, Type=RPi3, CPU=armv7l, REV=a02082.
      [OK] init system detected: systemd
      [SECTION] Saving configuration.
      [SECTION] Cleaning previous builds.
      ./configure: line 505: make: command not found
      [OK] Finished.
      [15:22:49] pi@openHABianPi:~/MySensors$ make
      -bash: make: command not found
      [15:29:14] pi@openHABianPi:~$ sudo apt-get install make
      E: dpkg was interrupted, you must manually run 'sudo dpkg --configure -a' to correct the problem.
      [15:29:22] pi@openHABianPi:~$ sudo dpkg --configure -a
      Setting up libpng12-0:armhf (1.2.50-2+deb8u2) ...
      Setting up libfontenc1:armhf (1:1.1.2-1) ...
      Processing triggers for libc-bin (2.19-18+deb8u6) ...
      [15:29:49] pi@openHABianPi:~$ sudo apt-get install make
      Reading package lists... Done
      Building dependency tree
      Reading state information... Done
      Suggested packages:
        make-doc
      The following NEW packages will be installed:
        make
      0 upgraded, 1 newly installed, 0 to remove and 1 not upgraded.
      Need to get 333 kB of archives.
      After this operation, 1,047 kB of additional disk space will be used.
      Get:1 http://mirrordirector.raspbian.org/raspbian/ jessie/main make armhf 4.0-8.1 [333 kB]
      Fetched 333 kB in 0s (758 kB/s)
      error: unable to resolve reference HEAD: Invalid argument
      fatal: cannot lock HEAD ref
      warning: etckeeper failed to commit changes in /etc using git
      Selecting previously unselected package make.
      (Reading database ... 26337 files and directories currently installed.)
      Preparing to unpack .../make_4.0-8.1_armhf.deb ...
      Unpacking make (4.0-8.1) ...
      Processing triggers for man-db (2.7.0.2-5) ...
      Setting up make (4.0-8.1) ...
      error: unable to resolve reference HEAD: Invalid argument
      fatal: cannot lock HEAD ref
      warning: etckeeper failed to commit changes in /etc using git
      Updating FireMotD available updates count ...
      [15:31:13] pi@openHABianPi:~$ cd MySensors
      [15:31:21] pi@openHABianPi:~/MySensors$ make
      gcc -MT build/drivers/Linux/log.o -MMD -MP -march=armv7-a -mtune=cortex-a7 -mfpu=neon-vfpv4 -mfloat-abi=hard -DMY_RADIO_NRF24 -DMY_GATEWAY_LINUX -DMY_DEBUG -D__RPI_BPLUS -DLINUX_ARCH_RASPBERRYPI -DMY_RX_MESSAGE_BUFFER_FEATURE -DMY_RF24_IRQ_PIN=15  -Ofast -g -Wall -Wextra  -I. -I./core -I./drivers/Linux -I./drivers/RPi -c drivers/Linux/log.c -o build/drivers/Linux/log.o
      make: gcc: Command not found
      Makefile:102: recipe for target 'build/drivers/Linux/log.o' failed
      make: *** [build/drivers/Linux/log.o] Error 127
      

      What's wrong?

      posted in OpenHAB
      patrick schaerer
      patrick schaerer
    • RE: SCT-013-030 Energy Meter

      @m1rk0
      In Line 95 is the following expression:
      if (Irms < 0.3) Irms = 0;

      Irms is RMS current. The expression sets all current smaller than 0.3 as 0.
      You can delete this line for smaller values.
      I suggest to use a SCT-013-005 instead of a SCT-013-030.

      posted in My Project
      patrick schaerer
      patrick schaerer
    • RE: SCT-013-030 Energy Meter

      I optimized my code with the help of Surge.
      I added a KWH reading on a restart of the node.
      Now it's Version 1.3

      posted in My Project
      patrick schaerer
      patrick schaerer
    • RE: SCT-013-030 Energy Meter

      As far as i understand there is a resistor built in the sct013 that prevents this voltage buildup. But i am not an electrician.

      posted in My Project
      patrick schaerer
      patrick schaerer
    • RE: Sending Variables to a arduino switch

      On my newest project I have several sensors on the same node. Some of those sensors demand values on Var1 and Var2.
      The code works fine so far, but I have to write those values all in the same number of digits. (sorry for my english) For example:
      Sensor 1 has V_Var1 422
      Sensor 2 has V_Var1 20
      In order to get the right value on my node I must write the value on Sensor2 in Vera like this: 020
      Otherwise Sensor 2 would receive a V_Var1 of 420.
      Also I had to write a workaround for the incoming message of the switch states. I receive a String and check if the first value is asci 48 for 0 or asci 49 for 1

      It looks to me that some memory in receiving values is left after a value is received. Is it possible to clear that memory?

      Here is the code I am talking about:

      /**
       * 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
       */
      
      #define SKETCH_NAME "Bewässerung"
      #define SKETCH_VERSION "0.7a"
      
      #include <MySensor.h>  
      #include <SPI.h>
      #include "DHT.h"
      #include <Wire.h>
      #include <BH1750.h>
      
      
      
      DHT dht;
      BH1750 lightMeter;
      
      
      int dhtpin = 47;
      int strom_beet_pin = 48;
      int first_hum_pin = 0;
      int first_temp_pin = 4;
      int first_valve_pin = 43;
      
      unsigned long timer_manual;
      unsigned long timer_umgebung;
      unsigned long timer_beet;
      unsigned long zeit_umgebung = 30;
      unsigned long zeit_beet = 50;
      unsigned long zeit_manual = 60;
      unsigned int helligkeit = 700; // Schwellenwert für Licht bei Bewässerung
      int feuchtigkeit = 50; // Schwellenwert für Erdfeuchtigkeit bei Bewässerung
      int temperatur = 25; //Schwellenwert für Erdtemperatur bei Bewässerung
      
      // 0 wasser ein, 1-4 hum, 5-8 temp, 9-12 valve, 13 DHT temp, 14 DHT hum, 15 light
      float beet_data[16];
      
      //definitions for mySensors
      #define DHT_TEMP_ID 13
      #define DHT_HUM_ID 14
      #define LIGHT_ID 15
      
      //Initialize MySensors
      MyTransportNRF24 transport(49, 53);
      MySensor gw(transport);
      MyMessage msg_temp(DHT_TEMP_ID, V_TEMP);
      MyMessage msg_hum(DHT_HUM_ID, V_HUM);
      MyMessage msg_light(LIGHT_ID, V_LIGHT_LEVEL);
      MyMessage msg_hum1(1,V_HUM);
      MyMessage msg_hum2(2,V_HUM);
      MyMessage msg_hum3(3,V_HUM);
      MyMessage msg_hum4(4,V_HUM);
      MyMessage msg_temp1 (5,V_TEMP);
      MyMessage msg_temp2 (6,V_TEMP);
      MyMessage msg_temp3 (7,V_TEMP);
      MyMessage msg_temp4 (8,V_TEMP);
      MyMessage msg_valve1 (9,V_LIGHT);
      MyMessage msg_valve2 (10,V_LIGHT);
      MyMessage msg_valve3 (11,V_LIGHT);
      MyMessage msg_valve4 (12,V_LIGHT);
      //Initialize mySensor Variables
      MyMessage msg_zeit_umgebung(DHT_TEMP_ID, V_VAR1);
      MyMessage msg_helligkeit(LIGHT_ID, V_VAR1);
      MyMessage msg_feuchtigkeit(1, V_VAR1);
      MyMessage msg_zeit_beet(1, V_VAR2);
      MyMessage msg_temperatur(5, V_VAR1);
      MyMessage msg_zeit_manual(9, V_VAR1);
      
      void setup() {
        // put your setup code here, to run once:
        Serial.begin(115200); 
        Serial1.begin(115200); 
        gw.begin(incomingMessage);
        gw.sendSketchInfo(SKETCH_NAME, SKETCH_VERSION);
        lightMeter.begin();
        dht.setup(dhtpin);
        
        pinMode(strom_beet_pin, OUTPUT);
        gw.present(DHT_TEMP_ID, S_TEMP);
        gw.present(DHT_HUM_ID, S_HUM);
        gw.present(LIGHT_ID, S_LIGHT_LEVEL);
        int i=0;
        for ( i=0;i<4;i++) {
          pinMode(first_valve_pin+i,OUTPUT);
          gw.present(i+1,S_HUM);
          gw.present(i+5,S_TEMP);
          gw.present(i+9, S_LIGHT);
          digitalWrite(first_valve_pin+i,HIGH);
        }
        getVariables();
        timer_umgebung = millis()-zeit_umgebung*1000;
        timer_beet = millis()-zeit_beet*1000;
        Serial.println("Initialized");
      }
      
      void loop() {
       gw.process(); 
        // Abfrage der Umgebungsdaten
      if (zeit_umgebung*1000 <= millis()- timer_umgebung) {
        umgebung();
        timer_umgebung = millis();
        Ausgabe();
      }
      //Abfrage der Beetdaten und evtl. Wässerung
      if (zeit_beet*1000 <= millis() - timer_beet) {
        beet();
        send_beet_data();
        wassern_entscheid();
        timer_beet = millis();
        getVariables();
      }
      for (int i=0;i<4;i++) {
        if (beet_data[9+i] == HIGH) {
        beet();
        wassern_entscheid();
        }
      }
      // Manuelle Wässerung nach zeit_manual ausschalten
      if (zeit_manual*1000 <= millis() - timer_manual && beet_data[0] == HIGH) {
        Serial.println("Manual time is up");
        for (int i=0;i<4;i++) {
          beet_data[i+9] = LOW;
          wasser(i,LOW);
          }
         beet_data[0] = LOW;
         }
      
            
      // Alle Timer nach Overflow von millis() zurücksetzen
      if (millis() < timer_umgebung) {
        timer_umgebung = millis();
        timer_beet = millis();
        timer_manual = millis();   
        }
      }
      
      void getVariables() {
        gw.request(DHT_TEMP_ID, V_VAR1);
        gw.request(LIGHT_ID, V_VAR1);
        gw.request(1, V_VAR1);
        gw.request(1, V_VAR2);
        gw.request(5, V_VAR1);
        gw.request(9, V_VAR1);
      }
      
      void wassern_entscheid() {
        /* kriterien: 
         *  Morgen oder Abend d.h. Lux unter bestimmtem Wert
         *  Feuchtigkeit Beet unter bestimmtem Wert
         *  Temperatur Beet über bestimmtem Wert ?
         */
         if (beet_data[0] == HIGH) {
          Serial.println("Manual Valve override");
         }
         else {
         
         if (beet_data[15] < helligkeit) {
          for (int i=0;i<4;i++) {
            if (beet_data[i+1] < feuchtigkeit) {
              if (beet_data[i+9] == LOW) wasser(i,HIGH);
            }
            else {
              if (beet_data[i+9] == HIGH) wasser(i,LOW);
            }
          }
         }
         else {
          for (int i=0;i<4;i++) {
            if (beet_data[i+9] == HIGH) wasser(i,LOW);
          }
         }
      }
      }
      
      void umgebung() {
        float temperature = dht.getTemperature();
        float humidity = dht.getHumidity();
        uint16_t lux = lightMeter.readLightLevel();
        gw.send(msg_temp.set(temperature,1));
        gw.send(msg_hum.set(humidity,1));
        gw.send(msg_light.set(lux,1));
        beet_data[13] = temperature;
        beet_data[14] = humidity;
        beet_data[15] = lux;
      }
      
      
      void beet() {
        digitalWrite(strom_beet_pin, HIGH);
        gw.wait(2000);
        int i=0;
        for(i = 0;i<4;i++) {
          int hum = analogRead(first_hum_pin+i);
          hum = map(hum,1023,0,0,100);
          beet_data[1+i] = hum;
          int rawvoltage= analogRead(first_temp_pin+i);
          rawvoltage = 1024 - rawvoltage;
          float temp= ((rawvoltage/1024.0) * 5000/10)-273.15;
          beet_data[5+i] = temp;
        }
        digitalWrite(strom_beet_pin, LOW);
      }
      
      
      void send_beet_data() {
          gw.send(msg_hum1.set(beet_data[1],1));
          gw.send(msg_hum2.set(beet_data[2],1));
          gw.send(msg_hum3.set(beet_data[3],1));
          gw.send(msg_hum4.set(beet_data[4],1));
          gw.send(msg_temp1.set(beet_data[5],1));
          gw.send(msg_temp2.set(beet_data[6],1));
          gw.send(msg_temp3.set(beet_data[7],1));
          gw.send(msg_temp4.set(beet_data[8],1));
          Serial.println("beet data sent");
      }
      
      void Ausgabe() {
        Serial.print("Hum: ");
       for (int i=0; i<4; i++) {
        Serial.print(beet_data[i+1]);
        Serial.print(" ");
       }
       Serial.print(" Temp: ");
       for (int i=0; i<4; i++) {
        Serial.print(beet_data[i+5]);
        Serial.print(" ");
       } 
       Serial.print(" Valve: ");
       for (int i=0; i<4; i++) {
        Serial.print(beet_data[i+9]);
        Serial.print(" ");
       }
       Serial.print(" Zeit Beet: ");
       Serial.print(millis() - timer_beet);
       Serial.println("finished");
       //Variabeln anzeigen
         Serial.print("Variables ");
         Serial.print(zeit_umgebung);
         Serial.print("  ");
         Serial.print(zeit_beet);
         Serial.print("  ");
         Serial.print(zeit_manual);
         Serial.print("  ");
         Serial.print(feuchtigkeit);
         Serial.print("  ");
         Serial.print(helligkeit);
         Serial.print("  ");
         Serial.print(temperatur);
         Serial.println("  ");
      }
      
      void wasser(int valve_nr,boolean state) {
          digitalWrite(first_valve_pin+valve_nr,!state);
          beet_data[valve_nr+9] = state;
          if (valve_nr == 0) gw.send(msg_valve1.set(state,1));
          if (valve_nr == 1) gw.send(msg_valve2.set(state,1));
          if (valve_nr == 2) gw.send(msg_valve3.set(state,1));
          if (valve_nr == 3) gw.send(msg_valve4.set(state,1));
      }
      
      void incomingMessage(const MyMessage &message) {
        int i;
        for (i=0;i<4;i++) {
           if (message.sensor == i+9) {
            if (message.type == V_LIGHT) {
              char buffer[10];
              char* empfang = message.getString(buffer);
              int asci = buffer[0];
              boolean state;
              if (asci == 49) state=HIGH;
              if (asci == 48) state = LOW;
              wasser(i,state);
              if (state == HIGH) beet_data[0] = HIGH;
              timer_manual = millis();
              Serial.print(" Valve: ");
              Serial.print(i+9);
              //Serial.print(" Empfangen:  ");
              //Serial.print(asci);
              Serial.print(" State: ");
              Serial.println(state);
            }
           }  
        }
        if (message.sensor == DHT_TEMP_ID && message.type == V_VAR1) zeit_umgebung = message.getULong();
        if (message.sensor == LIGHT_ID && message.type == V_VAR1) helligkeit = message.getInt();
        if (message.sensor == 1 && message.type == V_VAR1) feuchtigkeit = message.getInt();
        if (message.sensor == 1 && message.type == V_VAR2) zeit_beet = message.getULong();
        if (message.sensor == 5 && message.type == V_VAR1) temperatur = message.getInt();
        if (message.sensor == 9 && message.type == V_VAR1) zeit_manual = message.getULong();
      }
      
      
      posted in Vera
      patrick schaerer
      patrick schaerer
    • RE: SCT-013-030 Energy Meter

      @maciejka : you can change the value on column 98: minuten == 60
      "Minuten" is german for minutes. if you want to report every minute change the value to 1.

      @Surge86 : thank you for your improvements! I will compare our codes and hopefully learn a lot.
      I startet arduino programming in november and keep on learning.

      greets patrick

      posted in My Project
      patrick schaerer
      patrick schaerer
    • RE: Sending Variables to a arduino switch

      It should work. The variable1 appears in vera after the sensor had requested var1. (But Im not completely shure about that ... )

      posted in Vera
      patrick schaerer
      patrick schaerer
    • RE: Sending Variables to a arduino switch

      in the advanced tab all the way down at the bottom there are should be Variable1. Put a value in the field and save.
      the next time your device requests the variable, the new value will be sent.

      posted in Vera
      patrick schaerer
      patrick schaerer
    • RE: SCT-013-030 Energy Meter

      I made some changes in the software. There was a mistake in the kwh and I added a DHT-Sensor (see comment in the code).
      It works well. The kwh is reset on each restart. I probably will change that in the future.

      posted in My Project
      patrick schaerer
      patrick schaerer
    • RE: SCT-013-030 Energy Meter

      0_1454182054474_Bildschirmfoto 2016-01-30 um 20.26.32.png

      C1 is 100uF

      R1+2 are 15k

      posted in My Project
      patrick schaerer
      patrick schaerer
    • RE: SCT-013-030 Energy Meter

      Ok I tested it and it works fine. Because the reading of low current was not acurate I change readings up to 60W as 0W. I mesure the energy consumption of a room dryer that consumes about 1400W. Mabe SCT-013-005 would be more acurate in low current mesurements.

      posted in My Project
      patrick schaerer
      patrick schaerer
    • RE: Communicate from Vera to MySensor Node

      You can send variable 1-5
      Mabe this thread will help you:
      http://forum.mysensors.org/topic/2826/sending-variables-to-a-arduino-switch

      Greets
      Patrick

      posted in Vera
      patrick schaerer
      patrick schaerer
    • RE: Sending Variables to a arduino switch

      @BartE: Thank you for your corrections to the code. I changed that.

      Now the sketch works. All I did is to add a new repeaternode between the gateway and the receiving node. It was definetly a hardware problem (or the problem was solved in 1.5.3 update).

      The LED_Node_var sketch works!

      posted in Vera
      patrick schaerer
      patrick schaerer
    • RE: Sending Variables to a arduino switch

      delay is not the problem ... i changed the code to gw.wait(1000)
      Serial output is the same

      posted in Vera
      patrick schaerer
      patrick schaerer
    • RE: Sending Variables to a arduino switch

      @BartE said:

      @patrick-schaerer the problem in your code snipped is the delay(1000).

      This is a blocking call which blocks also your radio module from communicating. You have to use gw.wait(1000); i.s.o. delay. Now your plugin will receive data.

      ok Ill try that

      posted in Vera
      patrick schaerer
      patrick schaerer
    • RE: Sending Variables to a arduino switch

      The LED is not the problem. AnalogWrite works perfect.
      Serial out is:
      Requesting VAR1
      LED Level 255

      connecting at 9600
       ,pt=0,l=23,sg=0,st=ok:LED brightness via VAR1
       send: 5-5-13-0 s=255,c=3,t=12,pt=0,l=3,sg=0,st=ok:0.2 
      send: 5-5-13-0 s=0,c=0,t=3,pt=0,l=0,sg=0,st=ok: 
      Requesting VAR1 send: 5-5-13-0 s=0,c=2,t=24,pt=0,l=0,sg=0,st=ok: Requesting VAR1send: 5-5-13-0 s=0,c=2,t=24,pt=0,l=0,sg=0,st=ok: 
      LED Level: 255 
      read: 13-13-255 s=255,c=3,t=7,pt=0,l=0,sg=0: 
      Requesting VAR1send: 5-5-13-0 s=0,c=2,t=24,pt=0,l=0,sg=0,st=ok: 
      LED Level: 255 
      Requesting VAR1send: 5-5-13-0 s=0,c=2,t=24,pt=0,l=0,sg=0,st=ok: 
      LED Level: 255 
      Requesting VAR1send: 5-5-13-0 s=0,c=2,t=24,pt=0,l=0,sg=0,st=ok: 
      LED Level: 255 
      read: 13-13-255 s=255,c=3,t=7,pt=0,l=0,sg=0: 
      Requesting VAR1send: 5-5-13-0 s=0,c=2,t=24,pt=0,l=0,sg=0,st=ok: 
      LED Level: 255 
      Requesting VAR1send: 5-5-13-0 s=0,c=2,t=24,pt=0,l=0,sg=0,st=ok: 
      LED Level: 255 
      Requesting VAR1send: 5-5-13-0 s=0,c=2,t=24,pt=0,l=0,sg=0,st=ok: 
      LED Level: 255
      

      IncomingMessage routine is never executed

      posted in Vera
      patrick schaerer
      patrick schaerer
    • RE: Sending Variables to a arduino switch

      I tried to write a node that sets the brightness of an attached LED with the value of V_VAR1
      I did this based on the Power Meter & Water Meter Sketch

      unfortunately it doesn't work 😞 edit: it works now!
      here is the code:
      https://codebender.cc/sketch:221589

      posted in Vera
      patrick schaerer
      patrick schaerer
    • RE: Sending Variables to a arduino switch

      the one on codebender ... and I also tried 1.5
      and vera UI5

      posted in Vera
      patrick schaerer
      patrick schaerer
    • Sending Variables to a arduino switch

      I want to send variable 1 to a arduino switch, that is lightened with a LED. Variable 1 is the brightness of the led.
      I read several threads to that topic:
      http://forum.mysensors.org/topic/957/red-green-matrix-information-panel-with-real-time-clock
      http://code.mios.com/trac/mios_arduino-sensor/wiki/TipsAndTricks
      http://forum.mysensors.org/topic/80/getting-numbers-from-vera-to-a-sensor/6
      but they have syntax mysensors library doesn't recognise (mabe the changed with new versions)
      gw.getStatus(CHILD_ID, V_VAR1); for example
      In "TipsAndTricks" Case # 2 I'm not sure what radioId="4,255" is. Is that what is in vera altid?

      It would be great if someone could give a simple script to send a variable to a node and the code I should use in vera scene.
      TIA Patrick

      posted in Vera
      patrick schaerer
      patrick schaerer
    • RE: Send a confirmation text when a node operates

      VeraAlert plugin in combination with pushbullet works fine for me.
      I added a mysensors "motion sensor" as a trigger to my ultimaker. Now Iget a message to the phone when the print is finished.
      Greets paede

      posted in My Project
      patrick schaerer
      patrick schaerer
    • SCT-013-030 Energy Meter

      Hi all
      It's late and I finished the sketch for my Energy Meter. I'ts not tested yet, but the part for sct-reading is tested and works.
      In a few days more nanos arrive, then I can test it.

      /**
       * 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.
       *
       *******************************
       *
       * EnergyMeterSCT by Patrick Schaerer
       * This Sketch is a WattMeter used with a SCT-013-030 non invasive PowerMeter
       * see documentation for schematic
       * 
       * Special thanks to Surge, who optimized my code.
       * 
       * updated to mySensors Library 2.0
       */
      
      
      #define MY_RADIO_NRF24
      #define MY_REPEATER_FEATURE
      #define MY_DEBUG
      
      
      #include <SPI.h>
      #include <MySensors.h>  
      #include <EmonLib.h> 
       
      #define ANALOG_INPUT_SENSOR 1  // The digital input you attached your SCT sensor.  (Only 2 and 3 generates interrupt!)
      //#define INTERRUPT DIGITAL_INPUT_SENSOR-2 // Usually the interrupt = pin -2 (on uno/nano anyway)
      #define CHILD_ID 1              // Id of the sensor child
      
      EnergyMonitor emon1;
      
      MyMessage wattMsg(CHILD_ID,V_WATT);
      MyMessage kwhMsg(CHILD_ID,V_KWH);
      MyMessage msgKWH(CHILD_ID,V_VAR1);
      unsigned long SLEEP_TIME = 60000 - 3735; // sleep for 60 seconds (-4 seconds to calculate values)
      
      float wattsumme = 0;
      float kwh = 0;
      float wh = 0;
      int minuten = 0;  //vorher 61
      boolean KWH_received=false;
      
      //Humidity Sensor Code
      #include <DHT.h>  
      #define CHILD_ID_HUM 2
      #define CHILD_ID_TEMP 3
      #define HUMIDITY_SENSOR_DIGITAL_PIN 2
      DHT dht;
      float lastTemp;
      float lastHum;
      boolean metric = true; 
      MyMessage msgHum(CHILD_ID_HUM, V_HUM);
      MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
      
      //End of Humidity Sensor Code
      
      
      void setup()  
      {  
        //energy clamp code
        //gw.begin(incomingMessage, AUTO, true,0); 
        
        Serial.begin(115200);
        emon1.current(ANALOG_INPUT_SENSOR, 30);             // Current: input pin, calibration.
      
        
        double Irms = emon1.calcIrms(1480);  // initial boot to charge up capacitor (no reading is taken) - testing
        request(CHILD_ID,V_VAR1);
        //end of energy clamp code
      
      //Humidity Sensor Code
        dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN);   
        metric = getConfig().isMetric;
        //End of Humidity Sensor Code 
      }
      
      void presentation() {
        // Send the sketch version information to the gateway and Controller
        // Register this device as power sensor
      sendSketchInfo("Energy Meter SCT013", "2.0");
      present(CHILD_ID, S_POWER);
      present(CHILD_ID_HUM, S_HUM);
      present(CHILD_ID_TEMP, S_TEMP);
      
      }
      void loop()     
      { 
        
        //process();
      
        //KWH reveived check
        if (!KWH_received) request(CHILD_ID,V_VAR1);
        
        // power used each minute
        if (minuten < 60) {
          double Irms = emon1.calcIrms(1480);  // Calculate Irms only
          if (Irms < 0.3) Irms = 0;
          long watt = Irms*240.0; // default was 230 but our local voltage is about 240
          wattsumme = wattsumme+watt;
          minuten++;
          send(wattMsg.set(watt));  // Send watt value to gw
          
          Serial.print(watt);         // Apparent power
          Serial.print("W I= ");
          Serial.println(Irms);          // Irms   
        }
        // end power used each minute
        
        // hours KW reading
        if (minuten >= 60) {
          wh = wh + wattsumme/60;
          kwh = wh/1000;
          send(kwhMsg.set(kwh, 3)); // Send kwh value to gw 
          send(msgKWH.set(kwh, 3)); // Send kwh value to gw
          wattsumme = 0;
          minuten = 0;
        }
      // end of hourly KW reading
          
      // Humidity Sensor Code
       if (minuten == 15 || minuten == 30 || minuten == 45|| minuten == 60) {
          float temperature = dht.getTemperature();
          if (isnan(temperature)) {
            Serial.println("Failed reading temperature from DHT");
          } else if (temperature != lastTemp) {
            lastTemp = temperature;
          if (!metric) {
            temperature = dht.toFahrenheit(temperature);
          }
          send(msgTemp.set(temperature, 1));
          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;
            send(msgHum.set(humidity, 1));
            Serial.print("H: ");
            Serial.println(humidity);
        }
       }
      
       //End of Humidity Sensor Code
       wait(SLEEP_TIME);
      }
      
      void receive(const MyMessage &message) {
        if (message.type==V_VAR1) {  
          kwh = message.getFloat();
          wh = kwh*1000;
          Serial.print("Received last KWH from gw:");
          Serial.println(kwh);
          //send(kwhMsg.set(kwh, 3)); // Send kwh value to gw 
          KWH_received = true;
        }
      }
          
      
      
      

      The schematics for attaching of the sct-013-030 is shown in the picture.

      IMG_20160103_223443.jpg

      posted in My Project
      patrick schaerer
      patrick schaerer
    • RE: ESP8266 WiFi gateway port for MySensors

      Thanks for your work!
      I made my wifigateway today and added variables for a static IP Adress.
      I also tried to add an DHT11 to the wifi gateway, but it didn't work. I cannot include those sensors because I need to startup while inclusion and this would restart the gateway.
      Mabe someone has an Idea how to add a sensor to the wifi gateway. edit: I found this thread on the forum ... http://forum.mysensors.org/topic/1387/sensors-on-gateway

      /**
       * 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>
       * Contribution by Ivo Pullens (ESP8266 support)
       * 
       * DESCRIPTION
       * The EthernetGateway sends data received from sensors to the WiFi link. 
       * The gateway also accepts input on ethernet interface, which is then sent out to the radio network.
       *
       * 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.
       * The ESP8266 however requires different wiring:
       * nRF24L01+  ESP8266
       * VCC        VCC
       * CE         GPIO4          
       * CSN/CS     GPIO15
       * SCK        GPIO14
       * MISO       GPIO12
       * MOSI       GPIO13
       *            
       * Not all ESP8266 modules have all pins available on their external interface.
       * This code has been tested on an ESP-12 module.
       * The ESP8266 requires a certain pin configuration to download code, and another one to run code:
       * - Connect REST (reset) via 10K pullup resistor to VCC, and via switch to GND ('reset switch')
       * - Connect GPIO15 via 10K pulldown resistor to GND
       * - Connect CH_PD via 10K resistor to VCC
       * - Connect GPIO2 via 10K resistor to VCC
       * - Connect GPIO0 via 10K resistor to VCC, and via switch to GND ('bootload switch')
       * 
        * Inclusion mode button:
       * - Connect GPIO5 via switch to GND ('inclusion switch')
       * 
       * Hardware SHA204 signing is currently not supported!
       *
       * Make sure to fill in your ssid and WiFi password below for ssid & pass.
       */
      #define NO_PORTB_PINCHANGES 
      
      #include <SPI.h>  
      
      #include <MySigningNone.h> 
      #include <MySigningAtsha204Soft.h>
      #include <MyTransportNRF24.h>
      #include <MyTransportRFM69.h>
      #include <EEPROM.h>
      #include <MyHwESP8266.h>
      #include <ESP8266WiFi.h>
      
      #include <MyParserSerial.h>  
      #include <MySensor.h>  
      #include <stdarg.h>
      #include "GatewayUtil.h"
      
      
      const char *ssid =  "yourSSID";    // cannot be longer than 32 characters!
      const char *pass =  "yourPassword"; //
      IPAddress local_ip(192,168,0,6);
      IPAddress dns_address(192,168,0,1);
      IPAddress gateway_ip(192,168,0,1);
      IPAddress subnet(255,255,255,0);
      
      //Code for DHT Temp and Hum
      /*#include <DHT.h>  
      
      #define CHILD_ID_HUM 9
      #define CHILD_ID_TEMP 10
      #define HUMIDITY_SENSOR_DIGITAL_PIN 1
      long intervall = 300000; //read Temp and Hum every 5 minutes
      long last_millis = -300000;
      DHT dht;
      float lastTemp;
      float lastHum;
      boolean metric = true; 
      MyMessage msgHum(CHILD_ID_HUM, V_HUM);
      MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
      //End of Temp and Hum */
      
      #define INCLUSION_MODE_TIME 1 // Number of minutes inclusion mode is enabled
      #define INCLUSION_MODE_PIN  5 // Digital pin used for inclusion mode button
      
      #define RADIO_CE_PIN        4   // radio chip enable
      #define RADIO_SPI_SS_PIN    15  // radio SPI serial select
      
      #ifdef WITH_LEDS_BLINKING
      #define RADIO_ERROR_LED_PIN 7  // Error led pin
      #define RADIO_RX_LED_PIN    8  // Receive led pin
      #define RADIO_TX_LED_PIN    9  // the PCB, on board LED
      #endif
      
      
      // 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)
      #ifdef MY_SIGNING_FEATURE
      MySigningNone signer;
      //MySigningAtsha204Soft signer;
      #endif
      
      // Hardware profile 
      MyHwESP8266 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
      MySensor gw(transport, hw
      #ifdef MY_SIGNING_FEATURE
          , signer
      #endif
      #ifdef WITH_LEDS_BLINKING
        , RADIO_RX_LED_PIN, RADIO_TX_LED_PIN, RADIO_ERROR_LED_PIN
      #endif
        );
        
      
      #define IP_PORT 5003         // The port you want to open 
      #define MAX_SRV_CLIENTS 5    // how many clients should be able to telnet to this ESP8266
      
      // a R/W server on the port
      static WiFiServer server(IP_PORT);
      static WiFiClient clients[MAX_SRV_CLIENTS];
      static bool clientsConnected[MAX_SRV_CLIENTS];
      static inputBuffer inputString[MAX_SRV_CLIENTS];
      
      #define ARRAY_SIZE(x)  (sizeof(x)/sizeof(x[0]))
      
      
      void output(const char *fmt, ... )
      {
        char serialBuffer[MAX_SEND_LENGTH];
        va_list args;
        va_start (args, fmt );
        vsnprintf_P(serialBuffer, MAX_SEND_LENGTH, fmt, args);
        va_end (args);
        Serial.print(serialBuffer);
        for (uint8_t i = 0; i < ARRAY_SIZE(clients); i++)
        {
          if (clients[i] && clients[i].connected())
          {
      //       Serial.print("Client "); Serial.print(i); Serial.println(" write");
             clients[i].write((uint8_t*)serialBuffer, strlen(serialBuffer));
          }
        }
      }
      
      void setup()  
      { 
        // Setup console
        hw_init();
      
        Serial.println(); Serial.println();
        Serial.println("ESP8266 MySensors Gateway");
        Serial.print("Connecting to "); Serial.println(ssid);
      
        (void)WiFi.begin(ssid, pass);
        while (WiFi.status() != WL_CONNECTED)
        {
          delay(500);
          Serial.print(".");
        }
        Serial.println("Connected!");
        Serial.print("IP: "); Serial.println(WiFi.localIP());
        Serial.flush();
        
        (void)WiFi.config(local_ip, dns_address, gateway_ip, subnet);
        while (WiFi.status() != WL_CONNECTED)
        {
          delay(500);
          Serial.print(".");
        }
        Serial.println("Connected!");
        Serial.print("IP: "); Serial.println(WiFi.localIP());
        Serial.flush();
        
        
        setupGateway(INCLUSION_MODE_PIN, INCLUSION_MODE_TIME, output);
      
        // 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();
        server.setNoDelay(true);  
        
       /* //Code for Temp and Hum
        dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN); 
      
        // 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;
        //End of Temp and Hum */
      }
      
      
      void loop() {
        gw.process();  
        
        checkButtonTriggeredInclusion();
        checkInclusionFinished();
      
        // Go over list of clients and stop any that are no longer connected.
        // If the server has a new client connection it will be assigned to a free slot.
        bool allSlotsOccupied = true;
        for (uint8_t i = 0; i < ARRAY_SIZE(clients); i++)
        {
          if (!clients[i].connected())
          {
            if (clientsConnected[i])
            {
              Serial.print("Client "); Serial.print(i); Serial.println(" disconnected");
              clients[i].stop();
            }
            //check if there are any new clients
            if (server.hasClient())
            {
              clients[i] = server.available();
              inputString[i].idx = 0;
              Serial.print("Client "); Serial.print(i); Serial.println(" connected"); 
              output(PSTR("0;0;%d;0;%d;Gateway startup complete.\n"),  C_INTERNAL, I_GATEWAY_READY);
            }
          }
          bool connected = clients[i].connected();
          clientsConnected[i] = connected;
          allSlotsOccupied &= connected;
        }
        if (allSlotsOccupied && server.hasClient())
        {
          //no free/disconnected spot so reject
          Serial.println("No free slot available");
          WiFiClient c = server.available();
          c.stop();
        }
        
        // Loop over clients connect and read available data
        for (uint8_t i = 0; i < ARRAY_SIZE(clients); i++)
        {
          while(clients[i].connected() && clients[i].available())
          {
            char inChar = clients[i].read();
            if ( inputString[i].idx < MAX_RECEIVE_LENGTH - 1 )
            { 
              // if newline then command is complete
              if (inChar == '\n')
              {  
                // a command was issued by the client
                // we will now try to send it to the actuator
                inputString[i].string[inputString[i].idx] = 0;
          
                // echo the string to the serial port
                Serial.print("Client "); Serial.print(i); Serial.print(": "); Serial.println(inputString[i].string);
          
                parseAndSend(gw, inputString[i].string);
          
                // clear the string:
                inputString[i].idx = 0;
                // Finished with this client's message. Next loop() we'll see if there's more to read.
                break;
              } else {  
               // add it to the inputString:
               inputString[i].string[inputString[i].idx++] = inChar;
              }
            } else {
              // Incoming message too long. Throw away 
              Serial.print("Client "); Serial.print(i); Serial.println(": Message too long");
              inputString[i].idx = 0;
              // Finished with this client's message. Next loop() we'll see if there's more to read.
              break;
            }
          }
        }
       /* //Code for Temp and Hum
        if (millis() >= last_millis + intervall) {
          float temperature = dht.getTemperature();
          if (isnan(temperature)) {
            Serial.println("Failed reading temperature from DHT");
          } else if (temperature != lastTemp) {
            lastTemp = temperature;
          if (!metric) {
            temperature = dht.toFahrenheit(temperature);
          }
          gw.send(msgTemp.set(temperature, 1));
          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;
            gw.send(msgHum.set(humidity, 1));
            Serial.print("H: ");
            Serial.println(humidity);
        }
        last_millis = millis();
       }
        
       //End of Temp and Hum */
        
        
        
      }
      
      
      posted in Development
      patrick schaerer
      patrick schaerer
    • RE: Installing MySensors and Arduino IDE on OSX

      ok I installed Arduino IDE 1.6.6 and mysensors 1.5
      Now I can compile, but that IDE version doesn't work with my arduinos 😞
      avrdude: ser_open(): can't open device "/dev/cu.wchusbserial1420": Resource busy
      it seems a known problem with osx and serial bus ... I think I'll compile and upload with the windows pc

      posted in Troubleshooting
      patrick schaerer
      patrick schaerer
    • RE: Installing MySensors and Arduino IDE on OSX

      1.5 was a clean install. After that I deleted all libraries and installed 1.4 and it worked with 1.4.
      I tried to install 1.5 libraries over 1.4 but this did not help.
      I took mysensor.h from codebender, but that got even more errors 😞

      posted in Troubleshooting
      patrick schaerer
      patrick schaerer
    • Installing MySensors and Arduino IDE on OSX

      Hi
      I Installed Arduino IDE 1.0.6 and it works fine. I've compiled and uploaded sketches.
      I installed all the mysensors libraries from 1.5 release and this error happens when I compile and upload (HuniditySensor is just an example it happens on other sketches too):
      In file included from HumiditySensor.ino:31:
      /Users/patrickschaerer/Documents/Arduino/libraries/MySensors/MySensor.h:158: error: expected type-specifier before 'MyHwDriver'
      /Users/patrickschaerer/Documents/Arduino/libraries/MySensors/MySensor.h:158: error: default argument for parameter of type 'MyHw&' has type 'int'
      /Users/patrickschaerer/Documents/Arduino/libraries/MySensors/MySensor.h:158: error: expected ',' before 'MyHwDriver'

      I deleted all the libraries an installed mysensor libraries from 1.4 release. Compiling and uploading works fine on 1.4 release.

      Is there a bug in the 1.5 release or is something wrong with my installation?

      posted in Troubleshooting
      patrick schaerer
      patrick schaerer