LeClubSandwichStudio / LaCOOLBoard

Arduino library & sample sketches for La COOL Board, the open-source, open-hardware environmental monitoring and control device
http://www.lacool.co
MIT License
3 stars 5 forks source link

Reformat JSON API (currently a mess) #3

Open 3rwww1 opened 6 years ago

3rwww1 commented 6 years ago

Currently, the JSON API has a lot of issues

All in all,

We need to move to a software engineering perspective on doing things:

target format, as we discussed with @simon-lacool and @baltoche

{
  "static": {
    "hwVersion": "1.2.2",
    "macAddress": "60:01:94:1d:4c:b4",
    "ftdi": "...",
    "serialNumber": "CDC-2877-027"
  },
  "state": {
    "actuators": [
      false,
      false,
      false,
      false,
      false,
      false,
      false,
      false,
      false
    ],
    "system": {
      "fwVersion": "0.2.3",
      "timeSync": 1519814482,
      "manual": false,
      "publicIp": "178.20.51.116",
      "timestamp": "2018-03-01T10:56:33.000Z",
      "wifiSignal": -76,
      "batteryVoltage": 0.01,
    },
    "sensors": {
      "visibleLight": 289,
      "infraRed": 637,
      "ultraViolet": 0.45,
      "temperature": 24.22,
      "pressure": 992.38,
      "humidity": 36.45,
      "soilMoisture": 0,
      "ph": 7.56,
      "waterTemp": 24.56,
      "waterLevel": 5.4,
      "hydreon": 235456,
      "tipping": 245564,
      "wind": 3231321553,
      "ppfd": {
        "value": 6.7,
        "gain": 2
      },
      "waterMark": {
        "value": 6.3,
        "gain": 4
      },
      "color": {
        "temp": 4242,
        "r": 0.86,
        "g": 0.3,
        "b": 0.98,
        "c": 0.14
      }
    }
  },
  "config": {
    "general": {
      "ledActive": true,
      "logInterval": 300,
      "ireneActive": true,
      "jetpackActive": true,
      "externalSensorsActive": true,
      "serverTimeOut": 180,
      "sleepActive": false,
      "wifiSignal": true,
      "batteryVoltage": true,
      "mqttServer": "mqtts.lacoolbaord.io"
    },
    "sensors": {
      "builtIns": {
        "bme280": {
          "temperature": true,
          "humidity": true,
          "pressure": true
        },
        "st114X": {
          "visible": true,
          "ir": true,
          "uv": true
        },
        "soilMoisture": true,
      },
      "irene": {
        "waterTemp": {
          "active": true,
          "gain": 16
        },
        "ph": {
          "active": true,
          "gain": 16
        },
        "adc2": {
          "kind": "waterLevel",
          "active": false,
          "gain": true,
          "type": "voltage"
        },
        "calibration": {
          "pH7": 15092,
          "pH4": 20490,
          "step": -10.71064,
          "timestamp": "2018-02-27T09:31:42.000Z"
        }
      },
      "external": [
        {
          "reference": "CoolGauge",
          "type": "CoolGauge",
          "kind0": "tipping",
          "kind1": "hydreon",
          "kind2": "wind",
          "address": 0,
          "sensor3": "0",
          "kind3": "0"
        },
        {
          "reference": "NDIR_I2C",
          "type": "CO2",
          "connection": "I2C",
          "address": 77,
          "kind0": "0",
          "kind1": "0",
          "kind2": "0",
          "sensor3": "0",
          "kind3": "0"
        }
      ]
    },
    "actuators": [
      {
        "active": true,
        "inverted": true,
        "temporal": true,
        "low": [
          0,
          0,
          20,
          0
        ],
        "high": [
          0,
          0,
          6,
          0
        ],
        "type": {
          "primary": "hour"
        }
      },
      {
        "active": true,
        "inverted": true
      },
      {
        "active": true,
        "inverted": false
      },
      {
        "active": true,
        "inverted": false
      },
      {
        "active": true,
        "inverted": false
      },
      {
        "active": false,
        "inverted": false
      },
      {
        "active": false,
        "inverted": false
      },
      {
        "active": false,
        "inverted": true
      }
    ]
  }
}
trap98 commented 6 years ago

For the configuration i think take json name is better

trap98 commented 6 years ago

@3rwww1 First draft new single Json :

{
  "general": {
    "logInterval": 600,
    "ledActive":true,
    "ireneActive": true,
    "jetpackActive": true,
    "externalSensorsActive": true,
    "sleepActive": false,
    "mqttServer": "mqtts.lacoolboard.io"
  },
  "metrics": {
    "builtIns": {
      "BME280": {
        "temperature": true,
        "humidity": true,
        "pressure": true
      },
      "SI114X": {
        "visible": true,
        "ir": true,
        "uv": true
      },
      "vbat": true,
      "soilMoisture": true,
      "wallMoisture": false
    },
    "irene3000": {
      "waterTemp": {
            "active":1,
            "gain":16
        },
        "phProbe": {
            "active":1,
            "gain":16
        },
        "adc2": {
            "active":0,
            "gain":16,
            "type":"voltage"
        }
    },
    "externals": [
      {
        "reference":"SDS011",
        "type":"PM",
        "address":13,
        "kind0":"PM10",
        "kind1":"PM2.5"
      },
      {
        "reference":"NDIR_I2C",
        "type":"CO2",
        "address":77
      },
      {
        "reference": "SHT1x",
        "type": "SHT1x",
        "kind0": "SHT1x_Humidity",
        "kind1": "SHT1x_TempC"
      }
    ],
    "jetpack": [
      {
        "actif": false,
        "type": "time",
        "sensor": "",
        "inverted": false,
        "temporal": false,
        "low": {
          "range": 0,
          "time": 5000,
          "hour": 0,
          "minute": 0
        },
        "high":  {
          "range":0,
          "time": 5000,
          "hour": 0,
          "minute": 0
        }
      },
      {
        "actif":true,
        "type": "hour",
        "sensor": "",
        "inverted":true,
        "temporal":true,
        "low": {
          "range": 0,
          "time": 0,
          "hour": 20,
          "minute": 0
        },
        "high": {
          "range": 0,
          "time": 0,
          "hour": 7,
          "minute": 0
        }
      },
      {
        "actif":true,
        "type":"hour",
        "sensor":"",
        "inverted":true,
        "temporal":true,
        "low": {
          "range": 0,
          "time": 0,
          "hour": 23,
          "minute": 0
        },
        "high": {
          "range": 0,
          "time": 0,
          "hour": 6,
          "minute": 0
        }
      },
      {
        "actif":true,
        "type":"time",
        "sensor":"",
        "inverted":false,
        "temporal":true,
        "low": {
          "range": 0,
          "time": 600000,
          "hour": 0,
          "minute": 0
        },
        "high": {
          "range": 0,
          "time": 600000,
          "hour": 0,
          "minute": 0
        }
      },
      {
        "actif":true,
        "type":"time",
        "sensor":"",
        "inverted":false,
        "temporal":true,
        "low": {
          "range": 0,
          "time": 600000,
          "hour": 0,
          "minute": 0
        },
        "high": {
          "range": 0,
          "time": 600000,
          "hour": 0,
          "minute": 0
        }
      },
      {
        "actif":true,
        "type":"time",
        "sensor":"",
        "inverted":false,
        "temporal":true,
        "low": {
          "range": 0,
          "time": 600000,
          "hour": 0,
          "minute": 0
        },
        "high": {
          "range": 0,
          "time": 600000,
          "hour": 0,
          "minute": 0
        }
      },
      {
        "actif":true,
        "type":"range",
        "sensor":"CO2",
        "inverted":false,
        "temporal":true,
        "low": {
          "range": 1500,
          "time": 0,
          "hour": 0,
          "minute": 0
        },
        "high": {
          "range": 1500,
          "time": 0,
          "hour": 0,
          "minute": 0
        }
      },
      {
        "actif":false,
        "type":"range",
        "sensor":"Temperature",
        "inverted":false,
        "temporal":false,
        "low": {
          "range": 27,
          "time": 0,
          "hour": 0,
          "minute": 0
        },
        "high": {
          "range": 33,
          "time": 0,
          "hour": 0,
          "minute": 0
        }
      },
      {
        "actif":false,
        "type":"hour",
        "sensor":"",
        "inverted":true,
        "temporal":false,
        "low": {
          "range": 0,
          "time": 0,
          "hour": 6,
          "minute": 0
        },
        "high": {
          "range": 0,
          "time": 0,
          "hour": 18,
          "minute": 0
        }
      }
    ]