- Posts: 12
- Thank you received: 0
function getModuleData(module){
var data = {
icon: "",
status: "",
timestamp: "",
rawvalue: "", //TempPolazZad
unit: "",
rawvalue1: "", //SprGore
rawvalue2: "", //SprDole
rawvalue3: "", //Kotao
rawvalue4: "", //Dim
rawvalue5: "", //TempPolaz
rawvalue6: "", //Grijanje
};
data.icon = "user/" + Eiot.Data.ProfileId + "/images/fire.png";
var ic = Eiot.WebApp.Utility.GetModulePropertyByName(module, "Settings.Icon1");
if (ic != null && ic != "" && ic != "undefined")
data.icon = "user/" + Eiot.Data.ProfileId + "/images/" + ic.Value;
var level1 = Eiot.WebApp.Utility.GetModulePropertyByName(module, "Sensor.TempPolazZad");
if (level1 != null) {
data.unit = level1.Unit;
if (data.timestamp < level1.Timestamp)
data.timestamp = level1.Timestamp;
data.rawvalue = level1.Value;
var value = Math.round(level.Value.replace(",", ".") * 10) / 10;
if (isNaN(value)) value = level1.Value;
data.status =((level1.Description == "") ? "" : level1.Description + ": ") + value + ((level1.Unit == "") ? "" : " " + level1.Unit);
}
var level2 = Eiot.WebApp.Utility.GetModulePropertyByName(module, "Sensor.SprGore");
if (level2 != null) {
data.unit = level2.Unit;
if (data.timestamp < level2.Timestamp)
data.timestamp = level2.Timestamp;
data.rawvalue1 = level2.Value;
var value = Math.round(level2.Value.replace(",", ".") * 10) / 10;
if (isNaN(value)) value = level2.Value;
data.status += " " + ((level2.Description == "") ? "" : level2.Description + ": ") + value + ((level2.Unit == "") ? "" : " " + level2.Unit);
}
var level3 = Eiot.WebApp.Utility.GetModulePropertyByName(module, "Sensor.SprDole");
if (level3 != null) {
data.unit = level3.Unit;
if (data.timestamp < level3.Timestamp)
data.timestamp = level3.Timestamp;
data.rawvalue2 = level3.Value;
var value = Math.round(level3.Value.replace(",", ".") * 10) / 10;
if (isNaN(value)) value = level3.Value;
data.status += " " + ((level3.Description == "") ? "" : level3.Description + ": ") + value + ((level3.Unit == "") ? "" : " " + level3.Unit);
}
var level4 = Eiot.WebApp.Utility.GetModulePropertyByName(module, "Sensor.Kotao");
if (level4 != null) {
data.unit = level4.Unit;
if (data.timestamp < level4.Timestamp)
data.timestamp = level4.Timestamp;
data.rawvalue3 = level4.Value;
var value = Math.round(level4.Value.replace(",", ".") * 10) / 10;
if (isNaN(value)) value = level4.Value;
data.status += " " + ((level4.Description == "") ? "" : level4.Description + ": ") + value + ((level4.Unit == "") ? "" : " " + level4.Unit);
}
var level5 = Eiot.WebApp.Utility.GetModulePropertyByName(module, "Sensor.Dim");
if (level5 != null) {
data.unit = level5.Unit;
if (data.timestamp < level5.Timestamp)
data.timestamp = level5.Timestamp;
data.rawvalue4 = level5.Value;
var value = Math.round(level5.Value.replace(",", ".") * 10) / 10;
if (isNaN(value)) value = level5.Value;
data.status += " " + ((level5.Description == "") ? "" : level5.Description + ": ") + value + ((level5.Unit == "") ? "" : " " + level5.Unit);
}
var level6 = Eiot.WebApp.Utility.GetModulePropertyByName(module, "Sensor.TempPolaz");
if (level6 != null) {
data.unit = level6.Unit;
if (data.timestamp < level6.Timestamp)
data.timestamp = level6.Timestamp;
data.rawvalue5 = level6.Value;
var value = Math.round(level6.Value.replace(",", "."));
if (isNaN(value)) value = level6.Value;
data.status += " " + ((level6.Description == "") ? "" : level6.Description + ": ") + value + ((level6.Unit == "") ? "" : " " + level6.Unit);
}
var level7 = Eiot.WebApp.Utility.GetModulePropertyByName(module, "Sensor.Grijanje");
if (level7 != null) {
data.rawvalue6 = level7.Value;
var offText = "OFF";
var onText = "ON";
var o1 = Eiot.WebApp.Utility.GetModulePropertyByName(module, "Settings.StatusText2");
if (o1 != null)
offText = o1.Value;
var o2 = Eiot.WebApp.Utility.GetModulePropertyByName(module, "Settings.StatusText1");
if (o2 != null)
onText = o2.Value;
var level = Eiot.WebApp.Utility.GetModulePropertyByName(module, "Sensor.Grijanje");
data.status += " " + ((level7.Description == "") ? "" : level7.Description + ": ") + ((level7.Value == 0 ) ? offText : onText) + ((level7.Unit == "") ? "" : " " + level7.Unit);
}
return data;
}
function initControl(control)
{
var sliderVal;
var o4 = Eiot.WebApp.Utility.GetModulePropertyByName(module, "Sensor.TempPolazZad");
if (o4 != null) {
sliderVal = Math.round(o4.Value.replace(",", ".") * 100) / 100;
if (isNaN(sliderVal)) sliderVal = o4.Value;
}
var sliderMinValue = 35;
var sliderMaxValue = 70;
var sliderValueStep = 1;
var o1 = Eiot.WebApp.Utility.GetModulePropertyByName(module, "Settings.SliderMinValue");
if (o1 != null) {
sliderMinValue = Math.round(o1.Value.replace(",", ".") * 100) / 100;
if (isNaN(sliderMinValue)) sliderMinValue = o1.Value;
}
var o2 = Eiot.WebApp.Utility.GetModulePropertyByName(module, "Settings.SliderMaxValue");
if (o2 != null) {
sliderMaxValue = Math.round(o2.Value.replace(",", ".") * 100) / 100;
if (isNaN(sliderMaxValue)) sliderMaxValue = o2.Value;
}
var o3 = Eiot.WebApp.Utility.GetModulePropertyByName(module, "Settings.SliderStep");
if (o3 != null) {
sliderValueStep = Math.round(o3.Value.replace(",", ".") * 100) / 100;
if (isNaN(sliderValueStep)) sliderValueStep = o3.Value;
}
control.find("[data-ui-field=control_slider]").prop("min", sliderMinValue);
control.find("[data-ui-field=control_slider]").prop("max", sliderMaxValue);
control.find("[data-ui-field=control_slider]").prop("step", sliderValueStep);
control.find("[data-ui-field=control_slider]").slider();
control.find("[data-ui-field=control_slider]").val(sliderVal).slider("refresh");
control.find("[data-ui-field=control_slider]").on("slidestop", function(event, ui) { for (var j = 0; j < Eiot.Data.Modules.length; j++) {
if (Eiot.Data.Modules[j].Id == event.target.id)
{
var param = Eiot.WebApp.Utility.GetModulePropertyByName(Eiot.Data.Modules[j], "Sensor.TempPolazZad");
if (param != null){
Eiot.Data.ServiceCall("Control/Parameter/SetValue/"+param.Id+"/"+control.find("[data-ui-field=control_slider]").val(), null, "POST", null);
}
}
}
});
var state = "0";
var level = Eiot.WebApp.Utility.GetModulePropertyByName(module, "Sensor.Grijanje");
if (level != null && level.Value == "1")
state = "1";
var onText = "ON";
var o1 = Eiot.WebApp.Utility.GetModulePropertyByName(module, "Settings.StatusText1");
if (o1 != null)
onText = o1.Value;
var offText = "OFF";
var o1 = Eiot.WebApp.Utility.GetModulePropertyByName(module, "Settings.StatusText2");
if (o1 != null)
offText = o1.Value;
control.find(".ui-slider-label-a").text(onText);control.find(".ui-slider-label-b").text(offText);control.find("[data-ui-field=flipsw]").val(state).slider("refresh");control.find("[data-ui-field=flipsw]").on("change", function(event, ui) { for (var j = 0; j < Eiot.Data.Modules.length; j++) {
if (Eiot.Data.Modules[j].Id == event.target.id)
{
var param = Eiot.WebApp.Utility.GetModulePropertyByName(Eiot.Data.Modules[j], "Sensor.Grijanje");
if (param != null){
Eiot.Data.ServiceCall("Control/Parameter/SetValue/"+param.Id+"/"+control.find("[data-ui-field=flipsw]").val(), null, "POST", null);
}
}
}
});}
function updateControl(control, data)
{
control.find("[data-ui-field=control_slider]").val(data.rawvalue);
control.find("[data-ui-field=control_slider]").slider("refresh");
control.find("[data-ui-field=flipsw]").val(data.rawvalue6);
control.find("[data-ui-field=flipsw]").slider("refresh");
}
Please Log in or Create an account to join the conversation.
Please Log in or Create an account to join the conversation.
Please Log in or Create an account to join the conversation.
Please Log in or Create an account to join the conversation.
bmwmilos wrote: Thank you for replying. I will post the codes tomorrow. I need only the slider and switch,but i would also like to add 5 more sensors to display in status line like in the temperature and humidity example.
I did manage to get the controls working by selecting the MT_DIMMER module type and I thought that I could solve the problem of sensors by creating another module MT_Generic type. The second module gets created with different Id,and sensors get created and named correctly but even though i publish the values nothing gets to the cloud. Can I publish to two modules from the same client? Do i need to set up something different?
Please Log in or Create an account to join the conversation.
if (module.Parameters != null & module.Parameters > 2) {
for (var p = 2; p < module.Parameters.length; p++) {
if (module.Parameters[p].Name.substring(0, 7) == "Sensor.") {
data.status = data.status + ((module.Parameters[p].Description == "") ? module.Parameters[p].Name : module.Parameters[p].Description) + ": " + module.Parameters[p].Value + ((module.Parameters[p].Unit == "") ? "" : " " + module.Parameters[p].Unit) + "<br>";
if (data.timestamp < module.Parameters[p].Timestamp)
data.timestamp = module.Parameters[p].Timestamp;
}
}
}
Please Log in or Create an account to join the conversation.