Navigation

    • Register
    • Login
    • Search
    • OpenHardware.io
    • Categories
    • Recent
    • Tags
    • Popular
    1. Home
    2. Fredrik Carlsson
    • Profile
    • Following
    • Followers
    • Topics
    • Posts
    • Best
    • Groups

    Fredrik Carlsson

    @Fredrik Carlsson

    8
    Reputation
    40
    Posts
    889
    Profile views
    0
    Followers
    0
    Following
    Joined Last Online

    Fredrik Carlsson Follow

    Best posts made by Fredrik Carlsson

    • RE: Heatpump controller

      TOUCHDOWN!
      Here is working code. Whit this i can with mymqtt android app publish topic MyMQTT/20/1/V_LIGHT with message "1" for heatpump on (with 24 degrees etc etc) and "0" for heatpump off. I have tried it with my Panasonic heatpump and it works.
      I also added a little serial string in order to find out node Id (mine was 20 then)

      Next step is to increase the different modes.
      I was thinking from beginning of only having 5 different "hardcoded" modes that would actually be more then enough for my use, but it would be really nice to send over variables some how instead so you have complete control of the heatpump from OpenHAB (temp, heatingmode etc). I am just not sure about how long messages you can send with the nrf protocol. Must dig into that

      Thanks for all the help, as I said I have almost no programming nor Arduino knowledge since before. Just starting out.
      // Example sketch showing how to control ir Heatpumps
      // An IR LED must be connected to Arduino PWM pin 3.

            #include <Arduino.h>
            #include <FujitsuHeatpumpIR.h>
            #include <PanasonicCKPHeatpumpIR.h>
            #include <PanasonicHeatpumpIR.h>
            #include <CarrierHeatpumpIR.h>
            #include <MideaHeatpumpIR.h>
            #include <MitsubishiHeatpumpIR.h>
            #include <SamsungHeatpumpIR.h>
            #include <MySensor.h>
            #include <SPI.h>
            
            
            
            #define CHILD_1  1  // childId
            
            IRSender irSender(3); // pin where ir diode is sitting
            
            MySensor gw;
            MyMessage msg(CHILD_1, V_VAR1);
            
            HeatpumpIR *heatpumpIR[] = {new PanasonicCKPHeatpumpIR(), new PanasonicDKEHeatpumpIR(), new PanasonicJKEHeatpumpIR(),
                                        new PanasonicNKEHeatpumpIR(), new CarrierHeatpumpIR(), new MideaHeatpumpIR(),
                                        new FujitsuHeatpumpIR(), new MitsubishiFDHeatpumpIR(), new MitsubishiFEHeatpumpIR(),
                                        new SamsungHeatpumpIR(), NULL};
              // will take away everything except PanasonicJKE when everything ready to reduce sketch size
            
            void setup()  
            {  
            
              gw.begin(incomingMessage); // Start listening
            
              // Send the sketch version information to the gateway and Controller
              gw.sendSketchInfo("IR Sensor", "1.0");
            
              // Register a sensors to gw. Use binary light for test purposes.
              gw.present(CHILD_1, S_LIGHT);
              
              Serial.begin(9600); 
              delay(500);
            
              Serial.println(F("Starting"));
              Serial.print("Node Id is set to: ");
              Serial.println(gw.getNodeId());
            }
            
            
            void loop() 
            {
            
              gw.process();
             
            }
            
            
            
            void incomingMessage(const MyMessage &message) {
              // We only expect one type of message from controller. But we better check anyway.
              if (message.type==V_LIGHT) {
                 int incomingRelayStatus = message.getInt();
                 if (incomingRelayStatus == 1) {
                     
                      int i = 0; //counter
                      prog_char* buf;         
                   
                    do {
                   // Send the same IR command to all supported heatpumps
                            Serial.print(F("Sending IR to "));
                        
                            buf = (prog_char*)heatpumpIR[i]->model();
                            // 'model' is a PROGMEM pointer, so need to write a byte at a time
                            while (char modelChar = pgm_read_byte(buf++))
                            {
                              Serial.print(modelChar);
                            }
                            Serial.print(F(", info: "));
                        
                            buf = (prog_char*)heatpumpIR[i]->info();
                            // 'info' is a PROGMEM pointer, so need to write a byte at a time
                            while (char infoChar = pgm_read_byte(buf++))
                            {
                              Serial.print(infoChar);
                            }
                            Serial.println();
                        
                            // Send the IR command
                            heatpumpIR[i]->send(irSender, POWER_ON, MODE_HEAT, FAN_2, 24, VDIR_UP, HDIR_AUTO);
                            delay(500);
                          }
                            while (heatpumpIR[++i] != NULL);
               
                } else if (incomingRelayStatus == 0) {
                           
                      int i = 0; //counter
                      prog_char* buf;
                 
                  do {
                            // Send the same IR command to all supported heatpumps
                            Serial.print(F("Sending IR to "));
                        
                            buf = (prog_char*)heatpumpIR[i]->model();
                            // 'model' is a PROGMEM pointer, so need to write a byte at a time
                            while (char modelChar = pgm_read_byte(buf++))
                            {
                              Serial.print(modelChar);
                            }
                            Serial.print(F(", info: "));
                        
                            buf = (prog_char*)heatpumpIR[i]->info();
                            // 'info' is a PROGMEM pointer, so need to write a byte at a time
                            while (char infoChar = pgm_read_byte(buf++))
                            {
                              Serial.print(infoChar);
                            }
                            Serial.println();
                        
                            // Send the IR command
                            heatpumpIR[i]->send(irSender, POWER_OFF, MODE_HEAT, FAN_2, 24, VDIR_UP, HDIR_AUTO);
                            delay(500);
                          }
                          while (heatpumpIR[++i] != NULL);
             
             }
            }
            }
      posted in Development
      Fredrik Carlsson
      Fredrik Carlsson
    • RE: Node-Red as Controller

      Hello
      I have been tinkering a little with this and it does actually work.
      The only thing is that you must point the topic of the mqtt node directly to a child. Its not possible to just subscribe to topics higher in the hierarchy.

      For example in MyMQTT app on Android i can just subscribe to topic MyMQTT and then i get messages from all nodes connected to the Gateway. This is not possible with the mqtt node in NodeRED. You must specifically point it.
      below is and example of an mqtt node outputting to a debug node. My Gateway is at 192.168.1.201.

      [{"id":"d0ff7866.2f0088","type":"mqtt-broker","broker":"192.168.1.201","port":"1883","clientid":"MQTT"},{"id":"14e0544d.eb1fac","type":"debug","name":"","active":true,"console":"false","complete":"false","x":304,"y":827,"z":"cda8f31c.32571","wires":[]},{"id":"8792e08c.786d2","type":"mqtt in","name":"Temperatur","topic":"MyMQTT/21/1/V_TEMP","broker":"d0ff7866.2f0088","x":67.5,"y":791,"z":"cda8f31c.32571","wires":[["14e0544d.eb1fac"]]}]
      

      I am working on some code to push temperatures as an object trough a websocket for live viewing on a simple webpage.
      It maybe sounds advanced, but it is actually very easy. In my opinion Node-RED is just as powerfull as OpenHAB and not particulary more advanced either. Will post a full working example when i have everything ready.

      posted in Node-RED
      Fredrik Carlsson
      Fredrik Carlsson
    • RE: Node-Red as Controller

      ok so here is a example.
      please note, i am not a programmer so the code might not be the slickest, but it does its job.
      What this on is doing is basically emulating 3 mqtt inputs, whit options to see 2 different temperatures.
      Send it over via websocket and also use a http request node to serve a webpage straight from nodered, styled and everything, but without use for a server. Pretty nifty 🙂
      So now i must just create 3 temperature sensors and add them instead of the input nodes.

      Some pictures:
      Node-RED:
      nodered.PNG

      And the webpage generated at localhost:1880/temp:
      webpage.PNG

      Here is the code for the nodes:

      [{"id":"a770a428.588f58","type":"websocket-listener","path":"/admin/ws/temp","wholemsg":"false"},{"id":"40dd0e92.bf22f","type":"http in","name":"allow request on localhost:1880/temp","url":"/temp","method":"get","x":809,"y":578,"z":"cda8f31c.32571","wires":[["e2702220.1d8fe","baa85854.4557a8"]]},{"id":"e2702220.1d8fe","type":"template","name":"make HTTP response","field":"payload","template":"<!DOCTYPE HTML>\n<html>\n    <head>\n    <meta charset=\"utf-8\">\n    <meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">\n    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n    <title>Temp</title>\n\n    <!-- Bootstrap -->\n    <link rel=\"stylesheet\" href=\"https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css\">\n\n    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->\n    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->\n    <!--[if lt IE 9]>\n      <script src=\"https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js\"></script>\n      <script src=\"https://oss.maxcdn.com/respond/1.4.2/respond.min.js\"></script>\n    <![endif]-->\n    \n    </head>\n    <script type=\"text/javascript\">\n        var server = window.location.hostname;\n        var topics = {};\n        var wsUriC = \"ws://192.168.1.111:1880/admin/ws/temp\";\n        function wsConnectC() {\n            console.log(\"connect\",wsUriC);\n            var ws = new WebSocket(wsUriC);\n            ws.onmessage = function(msg) {\n               \n                var payloadObj = JSON.parse(msg.data);\n                console.log(payloadObj);\n\t\t\t\tvar output = \"\";\n\t\t\t\t\tfor (var property in payloadObj) {\n  \t\t\t\t\t\toutput += '<li class=\"list-group-item\"><strong>' +property + '</strong>' + ': ' + payloadObj[property]+'°C</li>';\n\t\t\t\t\t\t}\n                document.getElementById('messages').innerHTML = output;                                     \n              \n            }\n            ws.onopen = function() {\n                document.getElementById('status').innerHTML = \"<small>connected</small>\";\n                console.log(\"connected\");\n            }\n            ws.onclose = function() {\n                document.getElementById('status').innerHTML = \"not connected\";\n                setTimeout(wsConnectC,1000);\n            }\n        }\n    </script>\n    <body onload=\"wsConnectC();\" onunload=\"ws.disconnect;\">\n    <div class=\"container\">\n      <div class=\"panel panel-default\" margin: 15px;>\n  \t\t\t\t\t<div class=\"panel-heading\"><h3>Temperaturer</h3></div>\n       \t\t\t\t\t <div class=\"panel-body\" id=\"messages\">\n       \t\t\t\t\t <ul class=\"list-item\" id=\"messages\">\n       \t\t\t\t\t </ul>\n       \t\t\t\t\t \n       \t\t\t\t\t </div>\n        \t\t <div class=\"panel-footer\" id=\"status\"><small>disconnected</small></div>\n      </div>  \t\n     </div> \n    <script src=\"https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js\"></script>  \n    \n    </body>\n</html>","x":1156,"y":513,"z":"cda8f31c.32571","wires":[["ee850758.117af8"]]},{"id":"ee850758.117af8","type":"http response","name":"","x":1267,"y":439,"z":"cda8f31c.32571","wires":[]},{"id":"4f43f8f8.b0bc08","type":"websocket out","name":"","server":"a770a428.588f58","x":1226,"y":389,"z":"cda8f31c.32571","wires":[]},{"id":"77a6395f.8859c8","type":"function","name":"set topic Bedroom","func":"msg.topic=\"Bedroom\";\nreturn msg;","outputs":1,"x":298,"y":237,"z":"cda8f31c.32571","wires":[["e7a54f35.185ab"]]},{"id":"69bbfd9e.964404","type":"function","name":"set topic Kitchen","func":"msg.topic=\"Kitchen\";\nreturn msg;","outputs":1,"x":304,"y":319,"z":"cda8f31c.32571","wires":[["e7a54f35.185ab"]]},{"id":"e37062a.f1c8fa","type":"debug","name":"","active":true,"console":"false","complete":"false","x":1105,"y":238,"z":"cda8f31c.32571","wires":[]},{"id":"208f83d.fdf707c","type":"inject","name":"","topic":"","payload":"22.6","payloadType":"string","repeat":"","crontab":"","once":false,"x":109,"y":298,"z":"cda8f31c.32571","wires":[["69bbfd9e.964404"]]},{"id":"b9972cd4.4668d","type":"inject","name":"","topic":"","payload":"23.8","payloadType":"string","repeat":"","crontab":"","once":false,"x":109,"y":203,"z":"cda8f31c.32571","wires":[["77a6395f.8859c8"]]},{"id":"4ba6c90c.b45938","type":"inject","name":"","topic":"","payload":"24.7","payloadType":"string","repeat":"","crontab":"","once":false,"x":106,"y":409,"z":"cda8f31c.32571","wires":[["9d9cbe26.62634"]]},{"id":"e7a54f35.185ab","type":"function","name":"Add together all payloads and send over as JSON","func":"context.temp = context.temp || new Object();\n\nif (msg.payload == \"\") {\n\tmsg2 = new Object();\n\tmsg2 = context.temp;\n\tmsg.payload=JSON.stringify(msg2);\n\t} else {\n\tcontext.temp[msg.topic] = msg.payload;        \n\tmsg2 = new Object();\n\tmsg2 = context.temp;\n\tmsg.payload=JSON.stringify(msg2);\n\t};\n\n\treturn msg;\n\n","outputs":1,"x":847,"y":296,"z":"cda8f31c.32571","wires":[["e37062a.f1c8fa","4f43f8f8.b0bc08"]]},{"id":"9d9cbe26.62634","type":"function","name":"set topic Basement","func":"msg.topic=\"Basement\";\nreturn msg;","outputs":1,"x":310,"y":388,"z":"cda8f31c.32571","wires":[["e7a54f35.185ab"]]},{"id":"3cb28a44.c34d76","type":"inject","name":"","topic":"","payload":"22.6","payloadType":"string","repeat":"","crontab":"","once":false,"x":110,"y":240,"z":"cda8f31c.32571","wires":[["77a6395f.8859c8"]]},{"id":"89646127.769ba","type":"inject","name":"","topic":"","payload":"24.7","payloadType":"string","repeat":"","crontab":"","once":false,"x":107,"y":331,"z":"cda8f31c.32571","wires":[["69bbfd9e.964404"]]},{"id":"dbd016fe.242fe8","type":"inject","name":"","topic":"","payload":"23.8","payloadType":"string","repeat":"","crontab":"","once":false,"x":106,"y":376,"z":"cda8f31c.32571","wires":[["9d9cbe26.62634"]]},{"id":"baa85854.4557a8","type":"function","name":"send empty payload to send last known temperatures","func":"msg.payload=\"\";\nreturn msg;","outputs":1,"x":749,"y":528,"z":"cda8f31c.32571","wires":[["5a9cc578.a5633c"]]},{"id":"5a9cc578.a5633c","type":"delay","name":"Delay so websocket is started before sending","pauseType":"delay","timeout":"2","timeoutUnits":"seconds","rate":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":776,"y":487,"z":"cda8f31c.32571","wires":[["e7a54f35.185ab"]]}]
      posted in Node-RED
      Fredrik Carlsson
      Fredrik Carlsson
    • RE: Node-Red as Controller

      @vikasjee I am still working on my own system. Started to learn MongoDb and AngularJS so i am building my own frontend based on node-red as backend.

      There is another guy at the node-red maillist that has made a simple "mobile-app" based on node-red with a pure javascript/jquery setup. Check it out here: https://github.com/industrialinternet/Node-red-flows-mobile-web-app

      posted in Node-RED
      Fredrik Carlsson
      Fredrik Carlsson

    Latest posts made by Fredrik Carlsson

    • RE: Stable battery PIR Sensor

      I will try tomorrow to do it without any voltage regulators together with a sensebender micro. I have the bigger pir sensor though, but I dont think its much difference on thoose. We will see.

      posted in Hardware
      Fredrik Carlsson
      Fredrik Carlsson
    • RE: Stable battery PIR Sensor

      @m26872 Hello, have you not used any voltage regultator for the pir sensor? You just give it direct connection to the batterypack?

      posted in Hardware
      Fredrik Carlsson
      Fredrik Carlsson
    • RE: Heatpump controller

      Hello
      It would be nice to make it run on batteries, maybe with 10 seconds sleep, and then wake up only to check with gateway if there is a new command and then sleep again.

      I am building a pir sensor now based on 3*aa batteris running on 4,5 volt.I will ust use an LE33 step down directly after the battery pack to provide power to both sensebender+radio+pir. Dont know if that is the optimal way to do it but it should work

      posted in Development
      Fredrik Carlsson
      Fredrik Carlsson
    • RE: Heatpump controller

      @ToniA
      Hey, thanks for all the work you have put down. I have had some other projects going the last year so have not really put down more time on this.

      How is it working with the sensebender? Are you using it on batteries?
      Any ide about battery usage?

      posted in Development
      Fredrik Carlsson
      Fredrik Carlsson
    • RE: Stable battery PIR Sensor

      Wonderful!
      Maybe I will try this design then. But I dont need them so small so will probably use the bigger PIR sensor in mine.
      I will revert when I'm done

      posted in Hardware
      Fredrik Carlsson
      Fredrik Carlsson
    • Stable battery PIR Sensor

      Hello
      I am busy building an burglar alarm for my home.
      Because of this its important its a wireless system (to not go down during electrical failure in the house).

      I wonder is there any stable good PIR sensor that works with battery?
      I have sourced the forum but not really found anything. I have a couple of Sensebender micro boads lying around that I would prefer to use for this.

      Its off course also important that there is no false triggers, because then it would be a very unreliable system.

      posted in Hardware
      Fredrik Carlsson
      Fredrik Carlsson
    • RE: Measuring current

      @AWI

      Yes i am. but there is mistake in the picture the R3 is connected between Pin 3 and VCC, not ground (pull up resistor).

      Then that leaves me hanging a bit because that is way more than I will be comfortable with in terms off battery changes.
      Any suggestion what to do?

      posted in Hardware
      Fredrik Carlsson
      Fredrik Carlsson
    • RE: Measuring current

      @awi

      #include <MySensor.h>  
      #include <DHT.h>  
      
      #define CHILD_ID_HUM 0
      #define CHILD_ID_TEMP 1
      #define CHILD_ID_SWITCH 2
      #define BUTTON_PIN  3
      #define HUMIDITY_SENSOR_DIGITAL_PIN 4
      #define VBAT_PER_BITS 0.003363075 //(1mohm / 470 kohm)   Calculated volts per bit from the used battery montoring voltage divider.   Internal_ref=1.1V, res=10bit=2^10-1=1023, Eg for 3V (2AA): Vin/Vb=R1/(R1+R2)=470e3/(1e6+470e3),  Vlim=Vb/Vin*1.1=3.44V, Volts per bit = Vlim/1023= 0.003363075
      #define VMIN 1.9  // Battery monitor lower level. Vmin_radio=1.9V
      #define VMAX 3.3  //  " " " high level. Vmin<Vmax<=3.44
      int BATTERY_SENSE_PIN = A0;  // select the input pin for the battery sense point
      unsigned long SLEEP_TIME = 60000; // Sleep time between reads (in milliseconds)
      
      MySensor gw;
      DHT dht;
      float lastTemp;
      float lastHum;
      boolean metric = true; 
      int oldBatteryPcnt = 0;
      MyMessage msg(CHILD_ID_SWITCH,V_TRIPPED);
      MyMessage msgHum(CHILD_ID_HUM, V_HUM);
      MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
      
      
      void setup()  
      { 
        analogReference(INTERNAL);
        gw.begin();
        dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN); 
      
        // Send the Sketch Version Information to the Gateway
        gw.sendSketchInfo("Humidity", "1.0");
         // Setup the button
        pinMode(BUTTON_PIN,INPUT);
        // Activate internal pull-up
        digitalWrite(BUTTON_PIN,HIGH);
      
        // Register all sensors to gw (they will be created as child devices)
        gw.present(CHILD_ID_SWITCH, S_DOOR);
        gw.present(CHILD_ID_HUM, S_HUM);
        gw.present(CHILD_ID_TEMP, S_TEMP);
        
        metric = gw.getConfig().isMetric;
      }
      
      
      
      void loop()      
      {  
          // Get the update value
        int value = digitalRead(BUTTON_PIN);
       
        // Send in the new value
        gw.send(msg.set(value==HIGH ? 1 : 0));
        
        delay(dht.getMinimumSamplingPeriod());
      
        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);
        }
        
        int sensorValue = analogRead(BATTERY_SENSE_PIN);    // Battery monitoring reading
      //  Serial.println(sensorValue);
        float Vbat  = sensorValue * VBAT_PER_BITS;
      //  Serial.print("Battery Voltage: "); Serial.print(Vbat); Serial.println(" V");
       //int batteryPcnt = sensorValue / 10;
        int batteryPcnt = static_cast<int>(((Vbat-VMIN)/(VMAX-VMIN))*100.);   
      //  Serial.print("Battery percent: "); Serial.print(batteryPcnt); Serial.println(" %");
        if (oldBatteryPcnt != batteryPcnt) {
          gw.sendBatteryLevel(batteryPcnt);
          oldBatteryPcnt = batteryPcnt;
        }
      
      
      
        gw.sleep(BUTTON_PIN-2, CHANGE, SLEEP_TIME);
      }
      posted in Hardware
      Fredrik Carlsson
      Fredrik Carlsson
    • RE: Measuring current

      Hello again.
      I just got some new 470k resistors today so i changed out the 10k/4,7k resistors on the battery circuit to 1mohm/470k
      The current draw is now 0,63mA when sleeping and 17,6mA when sending.
      Especially the sleeping current seem very high. Any ideas to why?

      posted in Hardware
      Fredrik Carlsson
      Fredrik Carlsson
    • RE: Problems with powermeter pulse sensor

      hmm think i solved the problem. I tried with an arduino uno instead and now the sketch works fine. Very strange 😞

      posted in Troubleshooting
      Fredrik Carlsson
      Fredrik Carlsson