-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Additional local smappee REST API #16
Comments
snipplet from var baseURL = "/gateway/apipublic";
$(document).ready(function(){
loadConfig();
});
function resetActivePowerPeaks() {
if (!authenticated) setHeaderError("Error not authenticated. Use Logon first!");
else {
var url = baseURL + "/resetActivePowerPeaks";
$.ajax(
{
async : true,
type:'POST',
contentType: 'application/json',
url: url,
data: '',
dataType: 'son',
success: function(data) {
if (data.error) {
$("#advanced").hide();
setHeaderError(data.error);
}
else {
$("#advanced").show();
console.log("resetActivePowerPeaks success");
setHeader("Advanced Smappee tools...");
setContentInfo(data.content);
setHeaderSuccess(data.response);
}
},
error: function(data) {
console.log("resetActivePowerPeaks error");
alert("Error, "+data.responseText);
}
}
);
}
}
function resetIPScanCache() {
if (!authenticated) setHeaderError("Error not authenticated. Use Logon first!");
else {
var url = baseURL + "/resetIPScanCache";
$.ajax(
{
async : true,
type:'POST',
contentType: 'application/json',
url: url,
data: '',
dataType: 'son',
success: function(data) {
if (data.error) {
$("#advanced").hide();
setHeaderError(data.error);
}
else {
$("#advanced").show();
console.log("resetIPScanCache success");
setHeader("Advanced Smappee tools...");
setContentInfo(data.content);
setHeaderSuccess(data.response);
}
},
error: function(data) {
console.log("resetIPScanCache error");
alert("Error, "+data.responseText);
}
}
);
}
}
function resetSensorCache() {
if (!authenticated) setHeaderError("Error not authenticated. Use Logon first!");
else {
var url = baseURL + "/resetSensorCache";
$.ajax(
{
async : true,
type:'POST',
contentType: 'application/json',
url: url,
data: '',
dataType: 'son',
success: function(data) {
if (data.error) {
$("#advanced").hide();
setHeaderError(data.error);
}
else {
$("#advanced").show();
console.log("resetSensorCache success");
setHeader("Advanced Smappee tools...");
setContentInfo(data.content);
setHeaderSuccess(data.response);
}
},
error: function(data) {
console.log("resetSensorCache error");
alert("Error, "+data.responseText);
}
}
);
}
}
function clearData() {
if (!authenticated) setHeaderError("Error not authenticated. Use Logon first!");
else {
var url = baseURL + "/clearData";
$.ajax(
{
async : true,
type:'POST',
contentType: 'application/json',
url: url,
data: '',
dataType: 'son',
success: function(data) {
if (data.error) {
$("#advanced").hide();
setHeaderError(data.error);
}
else {
$("#advanced").show();
console.log("clearData success");
setHeader("Advanced Smappee tools...");
setContentInfo(data.content);
setHeaderSuccess(data.response);
}
},
error: function(data) {
console.log("clearData error");
alert("Error, "+data.responseText);
}
}
);
}
}
function clearAppliances() {
if (!authenticated) setHeaderError("Error not authenticated. Use Logon first!");
else {
var url = baseURL + "/clearAppliances";
$.ajax(
{
async : true,
type:'POST',
contentType: 'application/json',
url: url,
data: '',
dataType: 'son',
success: function(data) {
if (data.error) {
$("#advanced").hide();
setHeaderError(data.error);
}
else {
$("#advanced").show();
console.log("clearAppliances success");
setHeader("Advanced Smappee tools...");
setContentInfo(data.content);
setHeaderSuccess(data.response);
}
},
error: function(data) {
console.log("clearAppliances error");
alert("Error, "+data.responseText);
}
}
);
}
}
function restartSmappee() {
if (!authenticated) setHeaderError("Error not authenticated. Use Logon first!");
else {
var url = baseURL + "/restartSmappee?action=2";
$.ajax(
{
async : true,
type:'GET',
contentType: 'application/json',
url: url,
data: '',
dataType: 'son',
success: function(data) {
if (data.error) {
$("#advanced").hide();
setHeaderError(data.error);
}
else {
$("#advanced").show();
console.log("restartSmappee success");
setHeader("Advanced Smappee tools...");
setContentInfo(data.content);
setHeaderSuccess(data.response);
}
},
error: function(data) {
console.log("ledcontrol error");
alert("Error, "+data.responseText);
}
}
);
}
}
function loadConfig() {
var url = baseURL + "/advancedConfigPublic";
$.ajax(
{
async : true,
type:'POST',
contentType: 'application/json',
url: url,
data:"load",
dataType: 'son',
success: function(models) {
console.log("config load success");
setHeader("Monitor configuration");
if (models.error) {
setHeaderError(models.error);
}
else {
for (var i = 0; i < models.length; i++) {
var logRecord = models[i];
if (logRecord.key == "webPortalPassword") $("#webPortalPassword").val(logRecord.value);
if (logRecord.key == "activePowerLimitHigh") $("#activePowerLimitHigh").val(logRecord.value);
if (logRecord.key == "activePowerLimitLow") $("#activePowerLimitLow").val(logRecord.value);
if (logRecord.key == "mdnsHostName") $("#mdnsHostName").val(logRecord.value);
if (logRecord.key == "kWhDayBegin") $("#kWhDayBegin").val(logRecord.value);
if (logRecord.key == "kWhDayEnd") $("#kWhDayEnd").val(logRecord.value);
if (logRecord.key == "kWhNightBegin") $("#kWhNightBegin").val(logRecord.value);
if (logRecord.key == "kWhNightEnd") $("#kWhNightEnd").val(logRecord.value);
if (logRecord.key == "solarBegin") $("#solarBegin").val(logRecord.value);
if (logRecord.key == "solarEnd") $("#solarEnd").val(logRecord.value);
if (logRecord.key == "enableGreenBreathing") {
if (logRecord.value=="1") {
$('input:checkbox[name=enableGreenBreathing]')[0].checked = true;
}
else {
$('input:checkbox[name=enableGreenBreathing]')[0].checked = false;
}
}
if (logRecord.key == "enableLookAheadScheduleRecover") {
if (logRecord.value=="1") {
$('input:checkbox[name=enableLookAheadScheduleRecover]')[0].checked = true;
}
else {
$('input:checkbox[name=enableLookAheadScheduleRecover]')[0].checked = false;
}
}
if (logRecord.key == "enableMacAddressScanning") {
if (logRecord.value=="1") {
$('input:checkbox[name=enableMacAddressScanning]')[0].checked = true;
$("#arpScanParameters").parents("tr").show();
}
else {
$('input:checkbox[name=enableMacAddressScanning]')[0].checked = false;
$("#arpScanParameters").parents("tr").hide();
}
}
if (logRecord.key == "arpScanParameters") $("#arpScanParameters").val(logRecord.value);
}
}
},
error: function(data) {
console.log("config load error");
alert("Error, "+data.response);
}
}
);
}
function updateAndRestartEMeter() {
var url = baseURL + "/advancedConfigPublic";
$.ajax(
{
async : true,
type:'POST',
contentType: 'application/json',
url: url,
data:"save,webPortalPassword="+$("#webPortalPassword").val()+",arpScanParameters="+encodeURIComponent($("#arpScanParameters").val())+",mdnsHostName="+$("#mdnsHostName").val()+",activePowerLimitLow="+$("#activePowerLimitLow").val()+",activePowerLimitHigh="+$("#activePowerLimitHigh").val(),
dataType: 'son',
success: function(data) {
clearRefreshInterval();
console.log("config save success");
setHeader(data.header);
if (data.errror) setHeaderError(data.error);
if (data.success) setHeaderSuccess(data.success);
},
error: function(data) {
console.log("config save error");
alert("Error, "+data.response);
}
}
);
}
function autoCommissioningValidation(command) {
updateMeterIndexes();
console.log("stopAutoCommissioningValidation: "+command);
var url = baseURL + "/advancedConfigPublic";
$.ajax(
{
async : true,
type:'POST',
contentType: 'application/json',
url: url,
data:""+command+"",
dataType: 'son',
success: function(data) {
console.log("config save success");
setHeader(data.header);
if (data.errror) setHeaderError(data.error);
if (data.success) setHeaderSuccess(data.success);
},
error: function(data) {
console.log("config save error");
alert("Error, "+data.response);
}
}
);
}
function restartAutoCommissioningCyclus(command) {
updateMeterIndexes();
var url = baseURL + "/advancedConfigPublic";
$.ajax(
{
async : true,
type:'POST',
contentType: 'application/json',
url: url,
data:""+command+"",
dataType: 'son',
success: function(data) {
console.log("config save success");
setHeader(data.header);
if (data.errror) setHeaderError(data.error);
if (data.success) setHeaderSuccess(data.success);
},
error: function(data) {
console.log("config save error");
alert("Error, "+data.response);
}
}
);
}
function updateMeterIndexes() {
var url = baseURL + "/advancedConfigPublic";
$.ajax(
{
async : true,
type:'POST',
contentType: 'application/json',
url: url,
data:"updateMeterIndexes,kWhDayBegin="+$("#kWhDayBegin").val()+",kWhDayEnd="+$("#kWhDayEnd").val()+",kWhNightBegin="+$("#kWhNightBegin").val()+",kWhNightEnd="+$("#kWhNightEnd").val()+",solarBegin="+$("#solarBegin").val()+",solarEnd="+$("#solarEnd").val(),
dataType: 'son',
success: function(data) {
clearRefreshInterval();
console.log("config save success");
setHeader(data.header);
if (data.errror) setHeaderError(data.error);
if (data.success) setHeaderSuccess(data.success);
},
error: function(data) {
console.log("config save error");
alert("Error, "+data.response);
}
}
);
}
function enableGreenBreathing() {
var url = baseURL + "/advancedConfigPublic";
$.ajax(
{
async : true,
type:'POST',
contentType: 'application/json',
url: url,
data:"saveWithoutRestarting,enableGreenBreathing="+$("#enableGreenBreathing").prop("checked"),
dataType: 'son',
success: function(models) {
console.log("enableGreenBreathing");
if (models.error) {
setHeaderError(models.error);
}
},
error: function(data) {
console.log("enableGreenBreathing error");
alert("Error, "+data.response);
}
}
);
}
function enableLookAheadScheduleRecover() {
var url = baseURL + "/advancedConfigPublic";
$.ajax(
{
async : true,
type:'POST',
contentType: 'application/json',
url: url,
data:"saveWithoutRestarting,enableLookAheadScheduleRecover="+$("#enableLookAheadScheduleRecover").prop("checked"),
dataType: 'son',
success: function(models) {
console.log("enableLookAheadScheduleRecover");
if (models.error) {
setHeaderError(models.error);
}
},
error: function(data) {
console.log("enableLookAheadScheduleRecover error");
alert("Error, "+data.response);
}
}
);
}
function enableMacAddressScanning() {
var url = baseURL + "/advancedConfigPublic";
$.ajax(
{
async : true,
type:'POST',
contentType: 'application/json',
url: url,
data:"saveWithoutRestarting,enableMacAddressScanning="+$("#enableMacAddressScanning").prop("checked"),
dataType: 'son',
success: function(models) {
console.log("enableMacAddressScanning");
if (models.error) {
setHeaderError(models.error);
}
},
error: function(data) {
console.log("enableMacAddressScanning error");
alert("Error, "+data.response);
}
}
);
}
</script>
</head> |
snipplet from function refreshInstantaneous(){
$("#wfuDiv").hide();
var url = baseURL + "/instantaneous";
$.ajax(
{
async : true,
type:'POST',
contentType: 'application/json',
url: url,
data:"loadInstantaneous",
dataType: 'son',
success: function(models) {
setHeader("Monitor configuration");
if (models.error) {
setHeaderError(models.error);
} [...] var url = baseURL + "/configPublic";
$.ajax(
{
async : true,
type:'POST',
contentType: 'application/json',
url: url,
data:"load",
dataType: 'son',
success: function(models) {
console.log("config load success");
setHeader("Monitor configuration");
if (models.error) {
setHeaderError(models.error);
} [...] var url = baseURL + "/configPublic";
$.ajax(
{
async : true,
type:'POST',
contentType: 'application/json',
url: url,
data:"save,currentReverser0="+$("#currentReverser0").prop("checked")+",currentReverser1="+$("#currentReverser1").prop("checked")+",currentReverser2="+$("#currentReverser2").prop("checked")+",currentReverser3="+$("#currentReverser3").prop("checked")+",currentReverser4="+$("#currentReverser4").prop("checked")+",currentReverser5="+$("#currentReverser5").prop("checked")+",autoDetection="+$("#autoDetection").prop("checked")+",solarCTConfig="+$('input[name=solarCTConfig]:radio:checked').val()+",singleVoltageShift="+$('input[name=singleVoltageShift]:radio:checked').val()+",mainsFrequency="+$('input[name=mainsFrequency]:radio:checked').val()+",emeterConfiguration="+emeterConfigurationState+",phaseMapping="+getPhaseMapping()+",3PhaseConfig="+$('input[name=3PhaseConfig]:radio:checked').val(),
dataType: 'son',
success: function(data) {
testConfigUsed=false;
//clearRefreshInterval();
console.log("config save success");
setHeader(data.header);
if (data.errror) setHeaderError(data.error);
if (data.success) {
//setHeaderSuccess(data.success);
$('#contentArea').empty();
$('#contentArea').load('configpublic.html');
pleaseWaitApp.hidePleaseWait();
}
},
error: function(data) {
console.log("config save error");
alert("Error, "+data.response);
}
}
); |
snipplet from function loadConfig() {
var url = baseURL + "/commandControlPublic";
$.ajax(
{
async : true,
type:'POST',
contentType: 'application/json',
url: url,
data:"load",
dataType: 'json',
success: function(models) {
$("#commandControlDiv").show();
console.log("config load success");
setHeader("Monitor configuration");
if (models.error) {
setHeaderError(models.error);
$("#commandControlDiv").hide();
}
else {
$("#commandControlDiv").show();
buildControls(models);
}
},
error: function(data) {
console.log("config load error");
alert("Error, "+data.response);
}
}
);
}
function buildControls(models) {
//******************************************************* AngulerJs begin *******************************************************
// call the function in the controller scope to control the view
angular.element($('#controlDiv')).scope().bind(models);
angular.element($('#controlDiv')).scope().$apply();
//angular.element($('#controlDivTimed')).scope().bind(models);
//angular.element($('#controlDivTimed')).scope().$apply();
//******************************************************* AngulerJs end *******************************************************
}
function sendGroup() {
var url = baseURL + "/commandControlPublic";
$.ajax(
{
async : true,
type:'POST',
contentType: 'application/json',
url: url,
data:"controlGroup",
dataType: 'json',
success: function(data) {
console.log("control onOff success");
setHeader(data.header);
if (data.errror) setHeaderError(data.error);
if (data.success) setHeaderSuccess(data.success);
},
error: function(data) {
console.log("config save error");
alert("Error, "+data.response);
}
}
);
}
function onOffCommandControl(val) {
var url = baseURL + "/commandControlPublic";
$.ajax(
{
async : true,
type:'POST',
contentType: 'application/json',
url: url,
data:"control,controlId="+val.id,
dataType: 'json',
success: function(data) {
console.log("control onOff success");
setHeader(data.header);
if (data.errror) setHeaderError(data.error);
if (data.success) setHeaderSuccess(data.success);
},
error: function(data) {
console.log("config save error");
alert("Error, "+data.response);
}
}
);
}
function addCommandControl() {
var url = baseURL + "/commandControlPublic";
$.ajax(
{
async : true,
type:'POST',
contentType: 'application/json',
url: url,
data:"add,identifier="+$("#identifierChar").val()+$("#identifierNum").val()+",description="+$("#description").val()+",type="+$("#commandControlType").val(),
dataType: 'json',
success: function(models) {
console.log("add success");
if (models.error) {
setHeaderError(models.error);
}
else {
buildControls(models);
}
},
error: function(data) {
console.log("config save error");
alert("Error, "+data.response);
}
}
);
}
function deleteCommandControl(val) {
var url = baseURL + "/commandControlPublic";
$.ajax(
{
async : true,
type:'POST',
contentType: 'application/json',
url: url,
data:"delete,controlId="+val.id,
dataType: 'json',
success: function(models) {
console.log("delete success");
if (models.error) {
setHeaderError(models.error);
}
else {
buildControls(models);
}
},
error: function(data) {
console.log("config save error");
alert("Error, "+data.response);
}
}
);
}
function deleteCommandControlTimers(val) {
var url = baseURL + "/commandControlPublic";
$.ajax(
{
async : true,
type:'POST',
contentType: 'application/json',
url: url,
data:"deleteTimers,controlId="+val.id,
dataType: 'json',
success: function(models) {
console.log("delete success");
if (models.error) {
setHeaderError(models.error);
}
else {
buildControls(models);
}
},
error: function(data) {
console.log("config save error");
alert("Error, "+data.response);
}
}
);
}
function addCommandControlTimed() {
var selectedControl = $("#commandControlTypeTimed").val();
var url = baseURL + "/commandControlPublic";
$.ajax(
{
async : true,
type:'POST',
contentType: 'application/json',
url: url,
data:"addTimed,commandControlId="+$("#commandControlTypeTimed").val()+",hour="+$("#hour").val()+",min="+$("#min").val()+",day="+$("#day").val()+",act="+$("#act").val(),
dataType: 'json',
success: function(models) {
console.log("add success");
if (models.error) {
setHeaderError(models.error);
}
else {
buildControls(models);
$("#commandControlTypeTimed").val(selectedControl);
}
},
error: function(data) {
console.log("config save error");
alert("Error, "+data.response);
}
}
);
} |
snipplet from function loadWaveform() {
buildWaveformFilter();
var url = baseURL + "/waveformDisplay";
$.ajax(
{
async : true,
type:'POST',
contentType: 'application/json',
url: url,
data:"load,"+waveformFilter,
dataType: 'son',
success: function(models) {
buildVoltageGraph(models.voltageGraphData);
buildCurrentGraph(models.currentGraphData);
},
error: function(data) {
console.log("config load error");
alert("Error, "+data.response);
}
}
);
} |
snipplet from $(document).ready(function() {
//logFileList();
angular.element($('#controlDiv')).scope().logFileList();
});
var root='';
(function() {
var app = angular.module('logBrowserApp', []);
app.controller('logBrowserController', function ($scope, $http, $log) {
$scope.logFileList = function() {
$http({
method: 'POST',
url: root+'/gateway/apipublic/logBrowser',
data: 'logFileList',
headers: {
'Content-Type': 'application/json'
}
}).then(function successCallback(response) {
$log.log(response.data);
if (response.data.error) {
alert(response.data.error);
}
else {
$scope.logFileList = response.data;
}
}, function errorCallback(response) {
alert("Error requesting data..."+response);
$log.log(response);
});
}
$scope.logFileSelect = function(logFile) {
$http({
method: 'POST',
url: root+'/gateway/apipublic/logBrowser',
data: 'logFileSelect,'+logFile,
headers: {
'Content-Type': 'application/json'
}
}).then(function successCallback(response) {
if (response.data.error) {
alert(response.data.error);
}
else {
var link = document.createElement("a");
link.download = response.data.logFileName;
if (logFile.indexOf("/")==0) {
link.href = logFile; // smappee
}
else {
link.href = "/"+logFile; // windows and mac testing
}
link.click();
}
}, function errorCallback(response) {
alert("Error requesting data..."+response);
$log.log(response);
});
}
});
})(); |
I have added basically all functions listed above (except for Check them out in f80b59c All are untested, because I don't own a Smappee in my own local network. The more complex calls, which require many input values that I don't know or don't understand yet, are added as placeholders and will raise a @stefferber would you like to test some? |
With Google Chrome I was able to find additional details in:
The text was updated successfully, but these errors were encountered: