Cloud4RPi
Published © MIT

DIY hydroponics system powered by UniPi

DIY cloud connected hydroponics system powered by UniPi and Cloud4RPi

BeginnerFull instructions provided2 hours3,205
DIY hydroponics system powered by UniPi

Things used in this project

Hardware components

Raspberry Pi 2 Model B
Raspberry Pi 2 Model B
×1
Relay (generic)
×8
UniPi v1.1 extension board for Raspberry Pi
×1

Software apps and online services

Cloud4RPi
Cloud4RPi

Story

Read more

Code

Code snippet #1

Plain text
{
  "ts": /* Date & Time in ISO 8601 format */,
  "payload": [
    {"name": "Boolean Variable", "type": "bool" },
    {"name": "Numerical Variable", "type": "numeric" },
    {"name": "String Variable", "type": "string" }
  ]
}

Code snippet #2

Plain text
{
  "ts": /* Date & Time in ISO 8601 format */,
  "payload": [
    {"name": "Boolean Variable", "type": "bool" },
    {"name": "Numerical Variable", "type": "numeric" },
    {"name": "String Variable", "type": "string" }
  ]
}

Code snippet #3

Plain text
{ 
  "ts": /* Date & Time in ISO 8601 format */,
  payload: {
    "Variable Name": "Variable Value",
    "One more variable": 42,
    /* etc... */
    "Yet another variable": false
  }
}

Code snippet #4

Plain text
{ 
  "ts": /* Date & Time in ISO 8601 format */,
  payload: {
    "Variable Name": "Variable Value",
    "One more variable": 42,
    /* etc... */
    "Yet another variable": false
  }
}

Code snippet #5

Plain text
{
  "ts": /* Date & Time in ISO 8601 format */,
  payload: {
      "Diagnostic Variable": "Variable Value",
      "Another Diagnostic Variable": 12
  }
}

Code snippet #6

Plain text
{
  "ts": /* Date & Time in ISO 8601 format */,
  payload: {
      "Diagnostic Variable": "Variable Value",
      "Another Diagnostic Variable": 12
  }
}

Code snippet #9

Plain text
var message = {
    ts: new Date().toISOString(),
    payload: [ 
        {"name": "Bool Variable", "type": "bool"},
        {"name": "Number Variable", "type": "number"},
        {"name": "String Variable", "type": "string"}
    ]
};
return {payload: message};

Code snippet #10

Plain text
var message = {
    ts: new Date().toISOString(),
    payload: [ 
        {"name": "Bool Variable", "type": "bool"},
        {"name": "Number Variable", "type": "number"},
        {"name": "String Variable", "type": "string"}
    ]
};
return {payload: message};

Code snippet #11

Plain text
var getMsgValue = function(device, circuit){
  return msg.payload.filter(function(val){
      if(!val.dev){
          return false;
      }
      return val.dev === device && val.circuit === circuit;
  })[0].value;
};
var message = {
    ts: new Date().toISOString(),
    payload: {
        "Relay 1": getMsgValue("relay", "1") === 1,
        "Relay 2": getMsgValue("relay", "2") === 1,
        "Relay 3": getMsgValue("relay", "3") === 1,
        "Relay 4": getMsgValue("relay", "4") === 1,
        "Relay 5": getMsgValue("relay", "5") === 1,
        "Relay 6": getMsgValue("relay", "6") === 1,
        "Relay 7": getMsgValue("relay", "7") === 1,
        "Relay 8": getMsgValue("relay", "8") === 1
    }
};
return {payload: {message}};

Code snippet #12

Plain text
var getMsgValue = function(device, circuit){
  return msg.payload.filter(function(val){
      if(!val.dev){
          return false;
      }
      return val.dev === device && val.circuit === circuit;
  })[0].value;
};
var message = {
    ts: new Date().toISOString(),
    payload: {
        "Relay 1": getMsgValue("relay", "1") === 1,
        "Relay 2": getMsgValue("relay", "2") === 1,
        "Relay 3": getMsgValue("relay", "3") === 1,
        "Relay 4": getMsgValue("relay", "4") === 1,
        "Relay 5": getMsgValue("relay", "5") === 1,
        "Relay 6": getMsgValue("relay", "6") === 1,
        "Relay 7": getMsgValue("relay", "7") === 1,
        "Relay 8": getMsgValue("relay", "8") === 1
    }
};
return {payload: {message}};

Code snippet #13

Plain text
var message = {
    ts: new Date().toISOString(),
    payload: [ 
      {"name": "Relay 1", "type": "bool"},
      {"name": "Relay 2", "type": "bool"},
      {"name": "Relay 3", "type": "bool"},
      {"name": "Relay 4", "type": "bool"},
      {"name": "Relay 5", "type": "bool"},
      {"name": "Relay 6", "type": "bool"},
      {"name": "Relay 7", "type": "bool"},
      {"name": "Relay 8", "type": "bool"}
    ]
};
return {payload: message};

Code snippet #14

Plain text
var message = {
    ts: new Date().toISOString(),
    payload: [ 
      {"name": "Relay 1", "type": "bool"},
      {"name": "Relay 2", "type": "bool"},
      {"name": "Relay 3", "type": "bool"},
      {"name": "Relay 4", "type": "bool"},
      {"name": "Relay 5", "type": "bool"},
      {"name": "Relay 6", "type": "bool"},
      {"name": "Relay 7", "type": "bool"},
      {"name": "Relay 8", "type": "bool"}
    ]
};
return {payload: message};

Code snippet #15

Plain text
var circuit_number = parseInt(msg.circuit);
var valid_relay = circuit_number >= 1 && circuit_number <= 8;

if (msg.dev === "relay" && valid_relay){
    var relay_name = 'Relay ' + circuit_number;
    return {
        payload: {  
            ts: new Date().toISOString(),
            payload: {relay_name: msg.value === 1}
        }
    }
}

Code snippet #16

Plain text
var circuit_number = parseInt(msg.circuit);
var valid_relay = circuit_number >= 1 && circuit_number <= 8;

if (msg.dev === "relay" && valid_relay){
    var relay_name = 'Relay ' + circuit_number;
    return {
        payload: {  
            ts: new Date().toISOString(),
            payload: {relay_name: msg.value === 1}
        }
    }
}

Code snippet #17

Plain text
for (var var_name in msg.payload){
    if (var_name.indexOf('Relay ') >= 0){
        return {
            cmd: "set",
            dev: "relay",
            circuit: var_name.split(' ')[1],
            value: msg.payload[var_name] ? "1" : "0"
        }
    }
}

Code snippet #18

Plain text
for (var var_name in msg.payload){
    if (var_name.indexOf('Relay ') >= 0){
        return {
            cmd: "set",
            dev: "relay",
            circuit: var_name.split(' ')[1],
            value: msg.payload[var_name] ? "1" : "0"
        }
    }
}

Code snippet #19

Plain text
return { 
    payload: {
        "ts": new Date().toISOString(),
        payload: {
            "CPU Temperature": flow.get('cpuTemp'),
            "Uptime info": flow.get('uptimeInfo') || ""
        }
    }
}

Code snippet #20

Plain text
return { 
    payload: {
        "ts": new Date().toISOString(),
        payload: {
            "CPU Temperature": flow.get('cpuTemp'),
            "Uptime info": flow.get('uptimeInfo') || ""
        }
    }
}

Github

https://github.com/cloud4rpi/cloud4rpi

Github

https://github.com/UniPiTechnology/evok

Credits

Cloud4RPi

Cloud4RPi

0 projects • 13 followers
Cloud control panel for your IoT projects

Comments