Navigation

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

    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