Skip to content

Instantly share code, notes, and snippets.

Created Aug 18, 2018
What would you like to do?
@RequestMapping(value = "/data.json", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
JSONObject home() {
def data = ["hum_temp": "Temperatura (\u00b0C)", "hum_hum": "Wilgotno\u015b\u0107 (%)", "bar_pres_rel": "Ci\u015bnienie (hPa)", "lux": "Jasno\u015b\u0107 (lx)", "vbat": "Nap. baterii (V)", "vreg": "Nap. sensor\u00f3w (V)"]
def sensors = [:]
def readings = [:]
['Balkon', 'Salon', 'Biuro', 'Łazienka', 'Sypialnia', 'Piwnica'].eachWithIndex { String room, int idx ->
sensors << [(idx): ["label": room, "data": ["hum_temp", "hum_hum", "lux", "vbat", "vreg"]]]
readings << [(idx): ["id" : randomId, "stamp": timeStamp, "sensor_id": idx, "seq": randomId, "status": 0,
"flags" : randomId, "bar_temp": randomTemp, "bar_pres_abs": randomBarPress,
"bar_pres_rel": randomBarPress, "lux": randomLux, "hum_temp": randomTemp,
"hum_hum" : randomHumHum, "vbat": randomVBat, "vreg": randomVReg]]
["sensors": sensors, "readings": readings, "data": data]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment