Skip to content

Commit

Permalink
Solved lots of bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
loicortola committed Mar 16, 2019
1 parent 875f4cd commit c578ef1
Show file tree
Hide file tree
Showing 20 changed files with 1,034 additions and 1,557 deletions.
6 changes: 4 additions & 2 deletions bin/savelora.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ def setup(groupvars):
savelorapublicjwt = jwt.encode({
"sub": "001",
"name": "Public Idiot",
"iat": 1546297200
"iat": 1546297200,
"exp": 2147483647
}, constant.SAVE_LORA_API_PUBLIC_SECRET, algorithm='HS256').decode('utf-8')
saveloraproxyjwt = jwt.encode({
"sub": "007",
"name": "Trinity",
"iat": 1546297200
"iat": 1546297200,
"exp": 2147483647
}, constant.SAVE_LORA_API_PROXY_SECRET, algorithm='HS256').decode('utf-8')
saveloraadminsecret = ''.join(random.SystemRandom().choice(string.ascii_lowercase + string.ascii_uppercase + string.digits) for _ in range(64))
print("Save LoRa Public Server JWT is " + savelorapublicjwt)
Expand Down
110 changes: 0 additions & 110 deletions boilerplate/chapter1/README.md

This file was deleted.

46 changes: 27 additions & 19 deletions boilerplate/chapter1/src/api/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/
const Logger = require('../log/logger');
const conf = require('../conf');
const utils = require("../utils");
const axios = require('axios');

const authHeader = "Authorization";
Expand All @@ -20,14 +21,14 @@ const client = axios.create({

const deviceExists = async (devEUI) => {
try {
const response = await client.get(`/devices/${devEUI}`);
const response = await client.get(`/devices/${utils.normalizeHexString(devEUI)}`);
logger.debug("Response received", response.data);
return response;
} catch (e) {
if (e.response.status === 404) {
return false;
}
logger.error("Error occured during call to http api", e);
logger.error("Error occured during call to http api", e.message);
throw e;
}
};
Expand All @@ -49,70 +50,77 @@ const createDevice = async (device) => {
logger.debug("Response received", response.data);
return response;
} catch (e) {
logger.error("Error occured during call to http api", e);
logger.error("Error occured during call to http api", e.message);
throw e;
}
};


/**
* @param devEUI string
* @returns {Promise<boolean>}
*/
const deviceNwkKeyExists = async (devEUI) => {
try {
const response = await client.get(`/devices/${devEUI}/keys`);
const response = await client.get(`/devices/${utils.normalizeHexString(devEUI)}/keys`);
logger.debug("Response received", response.data);
return !!response;
} catch (e) {
if (e.response.status === 404) {
return false;
}
logger.error("Error occured during call to http api", e);
logger.error("Error occured during call to http api", e.message);
throw e;
}
};


/**
*
* @param devEUI {string} hex string
* @param nwkKey {string} hex string
* @param devEUI string
* (hex string)
* @param nwkKey string
* (hex string)
* @returns {Promise<*>}
*/
const updateDeviceNwkKey = async (devEUI, nwkKey) => {
try {
const response = await client.put(`/devices/${devEUI}/keys`, {
const response = await client.put(`/devices/${utils.normalizeHexString(devEUI)}/keys`, {
deviceKeys: {
devEUI: devEUI,
nwkKey: nwkKey
devEUI: utils.normalizeHexString(devEUI),
nwkKey: utils.normalizeHexString(nwkKey)
}
});
logger.debug("Response received", response.data);
return response;
} catch (e) {
logger.error("Error occured during call to http api", e);
logger.error("Error occured during call to http api", e.message);
throw e;
}
};

/**
*
* @param devEUI {string} hex string
* @param nwkKey {string} hex string
* @param devEUI string
* (hex string)
* @param nwkKey string
* (hex string)
* @returns {Promise<*>}
*/
const setDeviceNwkKey = async (devEUI, nwkKey) => {
try {
const response = await client.post(`/devices/${devEUI}/keys`, {
const response = await client.post(`/devices/${utils.normalizeHexString(devEUI)}/keys`, {
deviceKeys: {
devEUI: devEUI,
nwkKey: nwkKey
devEUI: utils.normalizeHexString(devEUI),
nwkKey: utils.normalizeHexString(nwkKey)
}
});
logger.debug("Response received", response.data);
return response;
} catch (e) {
if (e.response.status === 409) {
return await updateDeviceNwkKey(devEUI, nwkKey);
return await updateDeviceNwkKey(utils.normalizeHexString(devEUI), utils.normalizeHexString(nwkKey));
}
logger.error("Error occured during call to http api", e);
logger.error("Error occured during call to http api", e.message);
throw e;
}
};
Expand Down
2 changes: 1 addition & 1 deletion boilerplate/chapter1/src/progress/review-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const solveJoinRequestSupportedChallenge = async () => {
try {
challenge.content.messages.forEach(message => {
let packetDecoder = new JoinRequestPacketDecoder(message.topic, message.message);
result.content.messages.push({supported: packetDecoder.isSupported()});
result.content.messages.push({supported: !!packetDecoder.isSupported()});
});
} catch (e) {
if (!result.errors) {
Expand Down
57 changes: 0 additions & 57 deletions boilerplate/chapter2/README.md

This file was deleted.

5 changes: 3 additions & 2 deletions server/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
FROM node:slim

WORKDIR /server

COPY ./package.json /server/
Expand All @@ -10,5 +9,7 @@ COPY ./src /server/src

RUN npm install

ENV NODE_ENV=production

EXPOSE 3333
CMD [ "npm", "start" ]
CMD [ "npm", "start"]
5 changes: 4 additions & 1 deletion server/src/appserver/appserver-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ export const init = () => {
const checkDevices = async () => {
logger.debug("Checking devices");
let devices = await appServerClient.getRegisteredDevices();
if (!devices) {
return;
}
if (parseInt(devices.totalCount!) > 0) {
for (let d of devices.result!) {
let team = await teamDao.findByDevEUI(normalizeHexString(d.devEUI!));
Expand All @@ -54,7 +57,7 @@ const updateDeviceProgress = async (team: Team, d: DeviceDescriptor): Promise<bo
}
}
let deviceKeys = await appServerClient.getKeys(d.devEUI!);
if (!deviceKeys.nwkKey || normalizeHexString(deviceKeys.nwkKey!) !== normalizeHexString(config.loRaServer.targetNwkKey)) {
if (!deviceKeys || !deviceKeys.nwkKey || normalizeHexString(deviceKeys.nwkKey!) !== normalizeHexString(config.loRaServer.targetNwkKey)) {
return true;
}
// Device keys match the target. We can validate this step
Expand Down
Loading

0 comments on commit c578ef1

Please sign in to comment.