Skip to content
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

basic config manager #11

Merged
merged 7 commits into from
Jun 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions esp-alexa-relay/relay-a/v3/main/main.ino
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const byte relOFF[] = {0xA0, 0x01, 0x00, 0xA1};
template<typename T>
void debug(T &msg, bool newline = false) {
DEBUG_MODE = true;
Serial.begin(112500);
Serial.begin(115200);
DebugPrint(msg);
if (newline) DebugPrintln(F(""));
Serial.flush();
Expand All @@ -42,7 +42,7 @@ void debug(T &msg, bool newline = false) {
//
void configSetup() {
DEBUG_MODE = true;
Serial.begin(112500);
Serial.begin(115200);

// randomSeed(*(volatile uint32_t *)0x3FF20E44);
// String sApName = "ESPRELAY-" + String(random(111, 999));
Expand Down
Empty file.
9 changes: 9 additions & 0 deletions esp-rf/cc1101/relay/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# ESP RF Relay

- Listens for Sensors using [rtl_433_esp](https://github.com/NorthernMan54/rtl_433_ESP) and can relay to a http listener (ie NodeRed)
- Runs a http web server that accept params for a [rc-switch](https://github.com/sui77/rc-switch) signal and transmits the switch code

## Specs

- CC1101 RF Rx/Tx
- ESP32
14 changes: 14 additions & 0 deletions esp-rf/cc1101/relay/v1/data/control.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.16.0/jquery.validate.min.js"></script>
<script src="main.js"></script>
<title>RF Switch Relay</title>
</head>
<body bgcolor="#1F1F1F" >
<div style='text-align:center; height:96%; border:10px groove blue; border-radius: 5px;'>
<font size=+2><span style=color:#FFFDD2;>OK</span>
</div>
</body>
</html>
26 changes: 26 additions & 0 deletions esp-rf/cc1101/relay/v1/data/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="styles.css">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>ConfigManager</title>
</head>
<body>
<div class="container">
<h1 style="text-align: center;">Wifi Details</h1>
<form method="post" action="/">
<div class="field-group">
<label>SSID</label>
<input name="ssid" type="text" size="32">
</div>
<div class="field-group">
<label>Password</label>
<input name="password" type="text" size="64">
</div>
<div class="button-container">
<button type="submit">Save</button>
</div>
</form>
</div>
</body>
</html>
85 changes: 85 additions & 0 deletions esp-rf/cc1101/relay/v1/data/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
$( document ).ready(function() {

// get the config store
$.ajax({
url: '/settings',
success: function(data) {
$.each(data, function(key, value, data) {
var selector = '[name="' + key + '"]';
var target = $(selector);
if (target) {
console.log(selector);
if ( target.is("input") ) {
target.val(value);
} else {

}
}
});
}
});

var validationSettings = {
rules: {
deviceName: {
required: true
},
serverURL: {
required: true
},
frequency: {
required: true
},
receivePin: {
required: true
},
transmitPin: {
required: true
}
}
};

$.fn.serializeObject = function() {
var o = {};
var a = this.serializeArray();
$.each(a, function() {
var input = $("[name='" + this.name + "']");
var value = this.value;
var dataType = input[0].getAttribute("data-type");
if (dataType == "number") value = parseFloat(value);

if (o[this.name]) {
if (!o[this.name].push) {
o[this.name] = [o[this.name]];
}
o[this.name].push(value || '');
} else {
o[this.name] = value || '';
}
});
return o;
};

var settingForm = '[name="settingsForm"]';
$(settingForm).validate(validationSettings);
$(settingForm).on('submit', function(e) {
document.getElementById("status").innerHTML = ""
if($(this).valid()) {
e.preventDefault();
var formData = $(this).serializeObject();

$.ajax({
url: '/settings',
type: 'PUT',
data: JSON.stringify(formData),
contentType: 'application/json',
success: function(data) {
console.log(formData);
document.getElementById("status").innerHTML = "Settings Updated"
}
});

return false;
}
});
});
13 changes: 13 additions & 0 deletions esp-rf/cc1101/relay/v1/data/reset.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="styles.css">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Reset</title>
</head>
<body>
<div class="container">
<h1 style="text-align: center;">Reset</h1>
</div>
</body>
</html>
42 changes: 42 additions & 0 deletions esp-rf/cc1101/relay/v1/data/settings.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="styles.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.16.0/jquery.validate.min.js"></script>
<script src="main.js"></script>
<title>ConfigManager</title>
</head>
<body>
<div class="container">
<h1 style="text-align: center;">Settings</h1>
<form method="post" action="/settings" name="settingsForm">
<div class="field-group">
<label>Device Name</label>
<input name="deviceName" type="text" size="32" data-type="text">
</div>
<div class="field-group">
<label>Server URL</label>
<input name="serverURL" type="text" size="32" data-type="ntext">
</div>
<div class="field-group">
<label>Frequency</label>
<input name="frequency" type="text" size="8" data-type="number">
</div>
<div class="field-group">
<label>Receive Pin</label>
<input name="receivePin" type="text" size="2" data-type="number">
</div>
<div class="field-group">
<label>Transmit Pin</label>
<input name="transmitPin" type="text" size="2" data-type="number">
</div>
<div class="button-container">
<h2 style="" id="status"></h2>
<button type="submit">Save</button>
</div>
</form>
</div>
</body>
</html>
90 changes: 90 additions & 0 deletions esp-rf/cc1101/relay/v1/data/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
body {
color: #434343;
font-family: "Helvetica Neue",Helvetica,Arial,sans-serif;
font-size: 14px;
line-height: 1.42857142857143;
padding: 20px;
}
.container {
margin: 0 auto;
max-width: 400px;
}
form .error {
color: #8A1F11 !important;
border-color: #8A1F11;
}
label.error {
text-transform: none
}
p.error {
margin-bottom: 10px
}
p.inline-errors, p.error {
background: none
border-color: none
border: none
clear: both
font-size: 12px
}
form .field-group {
box-sizing: border-box;
clear: both;
padding: 4px 0;
position: relative;
margin: 1px 0;
width: 100%;
}
form .field-group > label {
color: #757575;
display: block;
margin: 0 0 5px 0;
padding: 5px 0 0;
position: relative;
word-wrap: break-word;
}
input[type=text] {
background: #fff;
border: 1px solid #d0d0d0;
border-radius: 2px;
box-sizing: border-box;
color: #434343;
font-family: inherit;
font-size: inherit;
height: 2.14285714em;
line-height: 1.4285714285714;
padding: 4px 5px;
margin: 0;
width: 100%;
}
input[type=text]:focus {
border-color: #4C669F;
outline: 0;
}
.button-container {
box-sizing: border-box;
clear: both;
margin: 1px 0 0;
padding: 4px 0;
position: relative;
width: 100%;
}
button[type=submit] {
box-sizing: border-box;
background: #f5f5f5;
border: 1px solid #bdbdbd;
border-radius: 2px;
color: #434343;
cursor: pointer;
display: inline-block;
font-family: inherit;
font-size: 14px;
font-variant: normal;
font-weight: 400;
height: 2.14285714em;
line-height: 1.42857143;
margin: 0;
padding: 4px 10px;
text-decoration: none;
vertical-align: baseline;
white-space: nowrap;
}
Loading