Skip to content

Commit

Permalink
Refactored JS code and updated Readme
Browse files Browse the repository at this point in the history
  • Loading branch information
foorschtbar committed Feb 12, 2022
2 parents 3c92a41 + 00aa7c8 commit c23537d
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 74 deletions.
32 changes: 18 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,27 @@
![](https://img.shields.io/github/license/foorschtbar/LoRaProMini?style=plastic)
](https://github.com/foorschtbar/LoRaProMini)

A LoRaWAN sensor node for The Things Network, based on an ATMEGA328P (Arduino Pro Mini) and RFM95W/SX1276 LoRa transiver module.
A LoRaWAN sensor node, based on ATmega328P MCU (Arduino Pro Mini) and RFM95W/SX1276 LoRa Transceiver.

![PCB Front Assembled](.github/pcb_front_assembled.png)
![PCB Front Assembled](.github/pcb_real.jpg)

The module can be used:

- Collect various climate values with environmental sensors. See [Environmental (Weather/Clima) Sensor](#environmental-weatherclima-sensor).
- Tell if the letter carrier has put new letters in your mailbox. See [Mailbox Monitor](#mailbox-monitor).
- Notify if someone rang the doorbell. See [Doorbell Monitor](#doorbell-monitor).
- Collect various climate values with environmental sensors. See [Environmental (Weather/Clima) Sensor](#environmental-weatherclima-sensor)
- Tell if the letter carrier has put new letters in your mailbox. See [Mailbox Monitor](#mailbox-monitor)
- Notify if someone rang the doorbell
- Act a wirless button
- and many more...

## Features

- Deep sleep MCU and sensors between data transmissions.
- Two interrupt inputs could use to wake up the MCU and sensors from deep sleep.
- Confirmend und unconfirmend data up messages.
- Ultra low power consumption. Under 10μA with all features and sensors.
- Deep sleep MCU and sensors between data transmissions
- Two interrupt inputs could use to wake up the MCU and sensors from deep sleep
- Confirmend und unconfirmend data up messages
- Ultra low power consumption. Under 10μA with all features and sensors
- Power input 3.5-6V:
- Battery (Li-Ion with 3.7V works fine)
- Battery (Li-Ion or Li-SOCl2 works fine)
- Battery with solar charger
- Sensor support
- Bosch BME280 (humidity, barometric pressure and ambient temperature)
Expand All @@ -42,18 +42,20 @@ The module can be used:

### Environmental (Weather/Clima) Sensor

- Download [Radiation Shield STL](https://www.prusaprinters.org/prints/73421-radiation-shield-for-diy-weather-station)
- Buy [Waterproof LED Solar Light](https://s.click.aliexpress.com/e/_9AKunB)

![Outdoor Clima Sensor](.github/outdoor_environmental_sensor.jpg)

### Mailbox Monitor

- Download [Case STL](https://www.prusaprinters.org/prints/132941-case-for-lorawan-mailbox-monitor-lorapromini)
- Buy [Normal Close Reed Switches](https://s.click.aliexpress.com/e/_A1mmAd)

![Mailbox Monitor](.github/outdoor_mailbox_monitor.jpg)

![Mailbox Monitor](.github/mailbox_full_small.gif) ![Mailbox Monitor](.github/mailbox_empty_small.gif)

### Doorbell Monitor

- TBD :warning:

## More pics

<!--- ![PCB Front](.github/pcb_front.png) --->
Expand All @@ -76,7 +78,7 @@ The module can be used:
1. Flash config firmware (See [How to flash](#how-to-flash))
1. Start voltage calibration from menu
1. Start configuration builder [Configuration Builder](https://foorschtbar.github.io/LoRaProMini/configbuilder)
1. Measure the voltage with a multimeter.
1. Measure the voltage with a multimeter
1. Insert multimeter voltage and the analog value in the Volts-per-bit (VPB) calculator to get VPB factor.
1. If u have a adjustable power supply, try different voltages to find best factor. Warning: The maximum voltage is 6 Volt
1. Fill out the other fields like activation methode, session keys and EUIs
Expand Down Expand Up @@ -222,6 +224,8 @@ function decodeUplink(input) {

- [ ] Go to sleep immediately when voltage is too low
- [ ] Multi point calibration for battery voltage
- [ ] Set ADR (On/Off)
- [ ] Set SF (7-12)
- [x] Add wake up trough interrupt pins
- [x] Move Major- and Minorversion byte to single byte. 4 bits for major and 4 bits for minor.
- [x] Add option for Confirmed Uplink to config
Expand Down
113 changes: 53 additions & 60 deletions configbuilder/script.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
$("form").on('click', 'button:not(:disabled)', function (e) {
// Run at document ready
$(document).ready((e) => {
makeConfig({
event: e
});
checkVPBInputs();
});

// Listen for events
$("form").on('click', 'button:not(:disabled)', (e) => {
e.preventDefault();
let field = $(this).prevAll("input, textarea");
let fieldname = $(this).prevAll("input, textarea").attr("id");
let field = $(e.target).prevAll("input, textarea");
let fieldname = $(e.target).prevAll("input, textarea").attr("id");

if ($(this).hasClass("generate")) {
if ($(e.target).hasClass("generate")) {
genStr = "";
if (formFields[fieldname] !== "undefined") {
datatypeLen = formFields[fieldname][1];
Expand All @@ -13,55 +22,49 @@ $("form").on('click', 'button:not(:disabled)', function (e) {
field.val(genStr).change();

}
} else if ($(this).hasClass("copy")) {
} else if ($(e.target).hasClass("copy")) {
field.focus();
field.select();
try {
document.execCommand('copy');
} catch (err) {}
} else if ($(this).hasClass("calc")) {
} else if ($(e.target).hasClass("calc")) {
$("#calc").toggle();
calcVPB();

} else if ($(this).hasClass("add")) {
} else if ($(e.target).hasClass("add")) {
let masterrow = $("#calc > div:first");
masterrow.clone().appendTo("#calc").find("input[type='text']").val("");
calcVPB();
checkVPBInputs();

} else if ($(this).hasClass("remove")) {
$(this).parent().remove();
} else if ($(e.target).hasClass("remove")) {
$(e.target).parent().remove();
calcVPB();
checkVPBInputs();
}

});

$("form").on('keyup change', '#calc input', function (e) {
calcVPB(e);
});

$(":not(#calc) input, select").on('keyup change', function (e) {
makeConfig(e);
});

$("#configStr").on('keyup blur change', function (e) {
makeConfig(e, true);
});

$(document).ready(function (e) {
makeConfig(e);
checkVPBInputs();
});

function checkVPBInputs() {
$("form").on('keyup change', '#calc input', (e) => calcVPB({
event: e
}));
$(":not(#calc) input, select").on('keyup change', (e) => makeConfig({
event: e
}));
$("#configStr").on('keyup blur change', (e) => makeConfig({
event: e,
fromInput: true
}));


const checkVPBInputs = () => {
$("#calc>div>button.add").prop("disabled", false).removeClass("btn-outline-secondary").addClass("btn-outline-success");
$("#calc>div>button.remove").prop("disabled", false).removeClass("btn-outline-secondary").addClass("btn-outline-danger");
$("#calc>div:not(:last-child)>button.add").prop("disabled", true).removeClass("btn-outline-success").addClass("btn-outline-secondary");
$("#calc>div:only-child>button.remove").prop("disabled", true).removeClass("btn-outline-danger").addClass("btn-outline-secondary");
}

function calcVPB(event) {
const calcVPB = (event) => {

let fields = $("#calc input");
let vpb = 0;
Expand All @@ -74,55 +77,42 @@ function calcVPB(event) {
let voltage = parseFloat(f1.val());
let analog = parseFloat(f2.val());

// if (f1.val().trim().length != 0) {
if (voltage == "" || isNaN(voltage) || f1.val().match(/,/g)) {
error = true;
f1.removeClass("is-valid").addClass("is-invalid");
} else {
f1.removeClass("is-invalid").addClass("is-valid");
}
// } else {
// error = true;
// f1.removeClass("is-invalid").removeClass("is-valid");
// }


// if (f2.val().trim().length != 0) {
if (analog == "" || isNaN(analog) || f2.val().match(/,/g)) {
error = true;
f2.removeClass("is-valid").addClass("is-invalid");
} else {
f2.removeClass("is-invalid").addClass("is-valid");
}
// } else {
// error = true;
// f2.removeClass("is-invalid").removeClass("is-valid");
// }

if (!error) {
vpb += (voltage / analog);
count++;
}

}

if (count > 0) {
vpb /= count;
}

$("#BAT_SENSE_VPB").val(VPB).change();

$("#BAT_SENSE_VPB").val(vpb).change();
}

function getConfigLen() {
const getConfigLen = () => {
let len = 0;
Object.keys(formFields).forEach(function (k) {
Object.keys(formFields).forEach((k) => {
len += parseInt(formFields[k][1]) * 2;
});
return len;
}

function getValidLen(str) {
const getValidLen = (str) => {
patt = /[^\s-]/g
validLen = str.length;
while (match = patt.exec(str)) {
Expand All @@ -131,7 +121,10 @@ function getValidLen(str) {
return validLen;
}

function makeConfig(event, parseConfig = false, checkOnly = false) {
const makeConfig = ({
event,
fromInput = false
}) => {
let errorMake = false;
let errorMsg = "";
let cfgStr = "";
Expand All @@ -141,7 +134,7 @@ function makeConfig(event, parseConfig = false, checkOnly = false) {
let configLen = getConfigLen();
let configLenWithCRC = getConfigLen() + 8;

if (parseConfig) {
if (fromInput) {
// Clean input
configStr.val(configStr.val().replace(/[^a-fA-F0-9]/g, ""));

Expand All @@ -153,7 +146,7 @@ function makeConfig(event, parseConfig = false, checkOnly = false) {
}

if (errorMsg == "") {
Object.keys(formFields).forEach(function (k) {
Object.keys(formFields).forEach((k) => {
let hexStr = "";
errorMsg = "";

Expand All @@ -167,7 +160,7 @@ function makeConfig(event, parseConfig = false, checkOnly = false) {
let dataGroup = formFields[k][3];

if (field.length) {
if (parseConfig) {
if (fromInput) {

// Extract bytes from configStr
hexSubStr = configStr.val().substr(pos, datatypeSize * 2);
Expand Down Expand Up @@ -333,14 +326,16 @@ function makeConfig(event, parseConfig = false, checkOnly = false) {
);
}

if (parseConfig) {
if (fromInput) {

if (errorMsg != "") {
configStr.removeClass("is-valid").addClass("is-invalid");
configStr.nextAll("div.invalid-feedback").html(errorMsg);
} else {
configStr.removeClass("is-invalid").addClass("is-valid");
makeConfig(event, false, true);
makeConfig({
event: event
});
}

} else {
Expand Down Expand Up @@ -409,7 +404,7 @@ const HexToFloat32 = (str) => {
} else return 0
}

function flipHexString(hexStr, hexDigits) {
const flipHexString = (hexStr, hexDigits) => {
h = "";

for (let i = 0; i < hexDigits; ++i) {
Expand All @@ -419,7 +414,7 @@ function flipHexString(hexStr, hexDigits) {
return h;
}

function formatHexStr(hexStr, length) {
const formatHexStr = (hexStr, length) => {
let strRtn = "";
for (i = 0; i < length; i++) {
if (i < hexStr.length) {
Expand All @@ -434,7 +429,7 @@ function formatHexStr(hexStr, length) {
return strRtn;
}

function padHexStr(hexStr, length) {
const padHexStr = (hexStr, length) => {

while (hexStr.length < length) {
hexStr = "0" + hexStr;
Expand All @@ -443,7 +438,7 @@ function padHexStr(hexStr, length) {
return hexStr;
}

var makeCRCTable = function () {
const makeCRCTable = () => {
var c;
var crcTable = [];

Expand All @@ -460,7 +455,7 @@ var makeCRCTable = function () {
return crcTable;
}

var crc32 = function (str) {
const crc32 = (str) => {
var crcTable = window.crcTable || (window.crcTable = makeCRCTable());
var crc = 0 ^ (-1);

Expand All @@ -469,6 +464,4 @@ var crc32 = function (str) {
}

return (crc ^ (-1)) >>> 0;
}

;
}

0 comments on commit c23537d

Please sign in to comment.