diff --git a/index.html b/index.html
index dc9883a..b8e6747 100644
--- a/index.html
+++ b/index.html
@@ -292,7 +292,7 @@
const lat = Math.floor(-38.661727955271765 * 1000000);
const lon = Math.floor(178.0236810462527 * 1000000);
console.log(lat, lon);
- await this.connection.sendCommandSetAdvertLatLon(lat, lon);
+ await this.connection.setAdvertLatLong(lat, lon);
},
async sendCommandAddUpdateContact() {
const publicKey = new Uint8Array([148, 63, 175, 162, 88, 212, 192, 40, 214, 185, 213, 140, 42, 145, 194, 186, 70, 71, 112, 68, 0, 192, 65, 4, 105, 143, 230, 50, 162, 79, 247, 192]);
diff --git a/src/connection/connection.js b/src/connection/connection.js
index c9ce694..fbc728a 100644
--- a/src/connection/connection.js
+++ b/src/connection/connection.js
@@ -434,6 +434,37 @@ class Connection extends EventEmitter {
});
}
+ setAdvertLatLong(latitude, longitude) {
+ return new Promise(async (resolve, reject) => {
+ try {
+
+ // resolve promise when we receive ok
+ const onOk = () => {
+ this.off(Constants.ResponseCodes.Ok, onOk);
+ this.off(Constants.ResponseCodes.Err, onErr);
+ resolve();
+ }
+
+ // reject promise when we receive err
+ const onErr = () => {
+ this.off(Constants.ResponseCodes.Ok, onOk);
+ this.off(Constants.ResponseCodes.Err, onErr);
+ reject();
+ }
+
+ // listen for events
+ this.once(Constants.ResponseCodes.Ok, onOk);
+ this.once(Constants.ResponseCodes.Err, onErr);
+
+ // set advert lat lon
+ await this.sendCommandSetAdvertLatLon(latitude, longitude);
+
+ } catch(e) {
+ reject(e);
+ }
+ });
+ }
+
setTxPower(txPower) {
return new Promise(async (resolve, reject) => {
try {