Я изменяю веб-сайт, который, когда пользователь нажимает кнопку, загружает файл json. Мне было интересно, есть ли способ, которым я мог бы автоматически получить это таким образом, чтобы я мог получить к нему доступ в AWS IoT Core.
По сути, микроконтроллер считывает информацию с машины, а затем размещает веб-сайт на своем собственном IP. Недостатком является то, что он работает, только если пользователь находится в той же сети, что и контроллер.
Я уже создал все необходимое для получения json в AWS IoT Core (из предыдущего проекта, где json уже отправлялся на AWS), мне просто нужен способ чтобы получить информацию там. Любая помощь будет более чем признательна. Спасибо!
РЕДАКТИРОВАТЬ: я думаю, что это должен быть необходимый код, однако я не уверен на 100%.
//Save the selected parameter values into the file
$(".SaveImg").click(function () {
//Step 1 : create the JSON for selected parameter values to be saved in file
//var SelectedSubParam = sel;
var str = "{\"ID\":" + sel + ",";
str += "\"param\": [";
//To define whether the selected parameters have value or not
var hasValue = false;
//To check whether parameters has selected or not
var isSelected = false;
$.fn.getSelectedParameterRows().each(function (idx, item) {
if ($(item).css("display") != "none") {
isSelected = true;
var paramValue = $(this).children().eq(1).children("input[type='text']").val().trim();
//Save the parameters which has value otherwise don't save it
if (paramValue != "" && ($(this).children().eq(1).children("input[type='text']").css("visibility") != 'hidden')) {
hasValue = true;
str += "{\"Name\":\"" + $(this).children().eq(0).text().trim() + "\",";
str += "\"Address\":\"" + $(this).children().eq(1).children("input[type='text']").attr('Id') + "\",";
str += "\"Value\":" + paramValue;
str += "},";
}
}
});
//Remove ',' from last param set to make a valid JSON
str = str.slice(0, -1);
str += "]}";
//Step 2: Create and save the Text file
if (hasValue) {
// To save text file in windows default location
// Commented since this code is not working for Mobiles
/*var txt = makeTextFile(str);
console.log($(".SaveImg").attr("href",txt));
$(".SaveImg").attr("download", "ParameterExport.txt");*/
// Create and save the file in downloads folder in client place using File saver API
var blob = new Blob([str], { type: "text/plain;base64" });
saveAs(blob, "ParameterExport.txt");
}
else if (!isSelected) {
if ($.fn.getParameterCount() > 0) {
alert("Please select Parameters !!");
}
else {
alert("No parameters available!!");
}
}
else {
//Show alert if all the selected parameters don't have the value
alert("File cannot be saved since selected variables don't have values !!");
}
});