-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactored project tree, implemented player repo logic and solution u…
…pdates
- Loading branch information
1 parent
f631e13
commit 225a9b7
Showing
124 changed files
with
447 additions
and
188 deletions.
There are no files selected for viewing
Binary file not shown.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/usr/bin/env python3 | ||
from gh import playerrepo | ||
import os | ||
os.chdir(os.path.dirname(os.path.realpath(__file__))) | ||
playerrepo.init_with_resources() | ||
playerrepo.commit_and_push_force() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/usr/bin/env python3 | ||
from gh import playerrepo | ||
import os | ||
import sys | ||
os.chdir(os.path.dirname(os.path.realpath(__file__))) | ||
playerrepo.clone_from_remote() | ||
|
||
if (len(sys.argv) != 3): | ||
print("Usage: python3 deploy_solution.py [chapter] [step]") | ||
print("Example: python3 deploy_solution.py chapter1 step-2") | ||
exit(1) | ||
playerrepo.deploy_solution(sys.argv[1], sys.argv[2]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import constant | ||
import tempfile | ||
import shutil | ||
import os | ||
from git import Repo | ||
|
||
tmpdir = tempfile.mkdtemp(suffix='player') | ||
repodir = tmpdir + "/repo" | ||
|
||
def init_with_resources(): | ||
print("Copying resources to " + repodir) | ||
shutil.copytree("../../resources/boilerplate", repodir, ignore=shutil.ignore_patterns("node_modules")) | ||
shutil.copytree("../../resources/course", repodir + "/course") | ||
|
||
|
||
def commit_and_push_force(): | ||
repo = Repo.init(repodir) | ||
origin = repo.create_remote('origin', constant.GIT_REPO) | ||
assert origin.exists() | ||
repo.git.add("--all") | ||
repo.git.commit(message="Initial Commit") | ||
repo.git.push("-f", "origin", "master") | ||
|
||
|
||
def clone_from_remote(): | ||
repo = Repo.clone_from(constant.GIT_REPO, repodir) | ||
assert repo.__class__ is Repo | ||
|
||
|
||
def deploy_solution(chapter, step): | ||
print("Copying solution from " + chapter + " / " + step) | ||
shutil.copytree("../../resources/solution/" + chapter + "/" + step, repodir + "/solution/" + chapter + "/" + step, ignore=shutil.ignore_patterns("node_modules")) | ||
repo = Repo(repodir) | ||
repo.git.add("--all") | ||
repo.git.commit(message="Added solution for " + chapter + " - " + step) | ||
repo.git.push("origin", "master") |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import servers | ||
import utils | ||
import constant | ||
import os | ||
os.chdir(os.path.dirname(os.path.realpath(__file__))) | ||
|
||
groupvars = [] | ||
servers.mqtt.setup(groupvars) | ||
servers.savelora.setup(groupvars) | ||
servers.saveloraweb.setup(groupvars) | ||
servers.loraserver.setup(groupvars) | ||
servers.dockers.setup(groupvars) | ||
|
||
utils.replace("../../" + constant.ANSIBLE_GROUPVARS_FILE, constant.ANSIBLE_BEGIN_TOKEN, constant.ANSIBLE_END_TOKEN, groupvars) |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
__snapshots__ | ||
dist | ||
node_modules | ||
.DS_Store | ||
*.iml | ||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Save-LoRa | ||
|
||
Welcome to the handson workshop **Save-LoRa**. | ||
|
||
Before you start, please read the following lines carefully. | ||
|
||
## Requirements | ||
* Compatible with Windows 8+ / Mac OSX / Linux | ||
* 1 USB Port available | ||
* Internet connection | ||
* Requires Node 8+ | ||
|
||
## Setup | ||
* Clone the current repository in your workspace | ||
* Browse to chapter1/ and Run `npm install`. This might take a while. | ||
* Browse to chapter2/ and Run `npm install`. This might take a while. | ||
|
||
## Game guide | ||
|
||
The game step-by-step guide is available here: [https://resourcepool.github.io/save-lora](https://resourcepool.github.io/save-lora) | ||
|
||
That's it! See you soon! |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
const api = require('./api/api'); | ||
const utils = require('./utils'); | ||
const mqtt = require('mqtt'); | ||
const conf = require('./conf'); | ||
const reviewService = require('./progress/review-service'); | ||
|
||
const Logger = require('./log/logger'); | ||
|
||
const JoinRequestPacketDecoder = require('./decoder/JoinRequestPacketDecoder'); | ||
|
||
const gatewayRxTopicRegex = new RegExp("^gateway/([0-9a-fA-F]+)/rx$"); | ||
|
||
const validAppEUI = utils.hexStringToBytes(conf.user.appEUI); | ||
const validMockAppEUI = utils.hexStringToBytes(conf.user.mockAppEUI); | ||
const deviceEUI = utils.hexStringToBytes(conf.user.deviceEUI); | ||
const deviceNetworkKey = utils.normalizeHexString(conf.user.nwkKey); | ||
|
||
const logger = Logger.child({service: 'index'}); | ||
let client; | ||
|
||
let init = () => { | ||
reviewService.init(); | ||
client = mqtt.connect(conf.mqtt.host, {username: conf.mqtt.username, password: conf.mqtt.password, clientId: conf.user.clientId}); | ||
client.on('connect', () => { | ||
client.subscribe('#', (err) => { | ||
if (err) { | ||
process.exit(1); | ||
} | ||
}); | ||
}); | ||
client.on("message", onMessage); | ||
|
||
}; | ||
|
||
/** | ||
* Step 2 | ||
* @param topic | ||
* @param message | ||
*/ | ||
let onMessage = async (topic, message) => { | ||
if (!gatewayRxTopicRegex.test(topic)) { | ||
return; | ||
} | ||
|
||
let msgDecoder = new JoinRequestPacketDecoder(topic, message); | ||
if (!msgDecoder.isSupported()) { | ||
return; | ||
} | ||
|
||
logger.debug("Join Request identified"); | ||
let decodedJoinRequest = msgDecoder.decode(); | ||
logger.debug("Decoded:" + JSON.stringify(decodedJoinRequest)); | ||
|
||
// Congratulations, you are decoding all the join requests of the LoRa network. | ||
// However, we want to be smart hackers and only activate your friend's device on the specific APP_EUI | ||
if (isValidAppEUI(decodedJoinRequest.appEUI) && isRightDeviceEUI(decodedJoinRequest.devEUI)) { | ||
logger.debug("AppEUI and DevEUI are valid. Will register device"); | ||
if (!await api.deviceExists(decodedJoinRequest.devEUI)) { | ||
await api.createDevice({ | ||
devEUI: decodedJoinRequest.devEUI, | ||
applicationID: conf.loRaServer.loRaApplicationId, | ||
deviceProfileID: conf.loRaServer.rak811DevProfileId, | ||
name: conf.user.clientId, | ||
description: '4242' | ||
}); | ||
} | ||
if (!await api.deviceNwkKeyExists(decodedJoinRequest.devEUI)) { | ||
await api.setDeviceNwkKey(decodedJoinRequest.devEUI, deviceNetworkKey); | ||
} | ||
logger.debug("Device registered successfully"); | ||
} | ||
}; | ||
|
||
/** | ||
* Check whether the AppEUI of the intercepted message is the one we want to work on | ||
* @param msgAppEUI string|Uint8Array | ||
* @returns {boolean} | ||
*/ | ||
let isValidAppEUI = (msgAppEUI) => { | ||
return utils.arraysEqual((typeof msgAppEUI === 'string') ? utils.hexStringToBytes(msgAppEUI) : msgAppEUI, validAppEUI) || utils.arraysEqual((typeof msgAppEUI === 'string') ? utils.hexStringToBytes(msgAppEUI) : msgAppEUI, validMockAppEUI); | ||
}; | ||
|
||
/** | ||
* Check whether the DeviceEUI equals the team's device. | ||
* If you don't implement this right, you might give a head start to all your competitors! | ||
* @param devEUI string|Uint8Array | ||
* @returns {boolean} | ||
*/ | ||
let isRightDeviceEUI = (devEUI) => { | ||
return utils.arraysEqual((typeof devEUI === 'string') ? utils.hexStringToBytes(devEUI) : devEUI, deviceEUI); | ||
}; | ||
|
||
init(); |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.