Skip to content

Commit

Permalink
Merge pull request #26 from Adam0Brien/usv-sensor-pod-to-cloud
Browse files Browse the repository at this point in the history
feat: Added Sensor-Pod to Beebotte Cloud Communication
  • Loading branch information
Adam O'Brien authored Apr 6, 2024
2 parents 79501a2 + 0f9d8c8 commit 1c22b35
Show file tree
Hide file tree
Showing 6 changed files with 145 additions and 8 deletions.
21 changes: 13 additions & 8 deletions USV/Sensor-Pod-Comms.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
// Starter Implementation
// Change on button A and B pressed to physical circuit
input.onButtonPressed(Button.A, function () {
isSubmerged = 0
})
input.onButtonPressed(Button.B, function () {
isSubmerged = 1
})
radio.onReceivedValue(function (name, value) {
if (name == "up") {
isSubmerged = 0
} else if (name == "down") {
isSubmerged = 1
}
})
let isSubmerged = 0
radio.setGroup(213)
basic.showIcon(IconNames.Yes)
radio.setGroup(73)
basic.showIcon(IconNames.Happy)
USVSensorPod.initLocalDisplay()
let ph_list: number[] = []
let light_list: number[] = []
let temp_list: number[] = []
isSubmerged = 1
isSubmerged = 0
basic.forever(function () {
USVSensorPod.ShowString("Temp:" + USVSensorPod.calculateTempC() + "°C", 0, 0)
USVSensorPod.ShowString("pH:" + USVSensorPod.calculatePh(), 0, 1)
USVSensorPod.ShowString("Temp:" + USVSensorPod.calculateTempC(), 0, 0)
USVSensorPod.ShowString("pH:" + USVSensorPod.calculatePh() + " " + "Light:" + USVSensorPod.getLight(), 0, 1)
})
basic.forever(function () {
if (isSubmerged == 1) {
Expand Down Expand Up @@ -50,7 +55,7 @@ basic.forever(function () {
if (isSubmerged == 0) {
for (let value of temp_list) {
radio.sendValue("tempC", value)
basic.pause(100)
basic.pause(1000)
temp_list.removeAt(temp_list.indexOf(value))
}
}
Expand Down
73 changes: 73 additions & 0 deletions USV/USV-SensorPod-Cloud.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
function parseJsonMessage (message: string) {
led.toggle(0, 4)
output_value = parseFloat(message.substr(message.indexOf(":") + 1, 9))
lenght = message.length - convertToText(output_value).length
lenght = lenght - 20
output_id = message.substr(1, lenght)
radio.sendValue(output_id, output_value)
}
function serialPrintMQTTMessage (text: string) {
led.toggle(1, 4)
serial.writeLine("Start")
serial.writeLine(text)
serial.writeLine("End")
}
microIoT.microIoT_MQTT_Event(microIoT.TOPIC.topic_4, function (message) {
USV.deployDirection(USV.SensorDeploy.down, 1)
basic.pause(2000)
USV.deployDirection(USV.SensorDeploy.up, 1)
sendIFTTTPost()
})
function sendIFTTTPost () {
return microIoT.microIoT_http_post(
tempC,
pH,
light2,
10000
)
}
radio.onReceivedValue(function (name, value) {
if (name == "tempC") {
microIoT.microIoT_SendMessage("{\"" + name + "\":" + value + "}", microIoT.TOPIC.topic_0)
tempC = convertToText(value)
led.toggle(4, 4)
} else if (name == "pH") {
microIoT.microIoT_SendMessage("{\"" + name + "\":" + value + "}", microIoT.TOPIC.topic_1)
pH = convertToText(value)
led.toggle(4, 4)
} else if (name == "light") {
microIoT.microIoT_SendMessage("{\"" + name + "\":" + value + "}", microIoT.TOPIC.topic_2)
light2 = convertToText(value)
led.toggle(4, 4)
}
})
function sendToNode (inputX: string, val: number, toggleX: number, toggleY: number) {
radio.sendValue(inputX, val)
led.toggle(toggleX, toggleY)
basic.pause(delay)
led.toggle(toggleX, toggleY)
}
let light2 = ""
let pH = ""
let tempC = ""
let output_id = ""
let lenght = 0
let output_value = 0
let delay = 0
basic.showString("Server")
delay = 1000
microIoT.microIoT_WIFI("SKYRRZ2S", "CyGKfu4VffGe")
microIoT.microIoT_MQTT(
"hYn5IyqJh7U9lfVdiSvSyJb1",
"ExMVG1hBAbrE0MFpyEwJJGJXAlT6zYwr",
"USVSensorPod/tempC",
microIoT.SERVERS.Global
)
microIoT.microIoT_add_topic(microIoT.TOPIC.topic_1, "USVSensorPod/pH")
microIoT.microIoT_add_topic(microIoT.TOPIC.topic_2, "USVSensorPod/light")
microIoT.microIoT_add_topic(microIoT.TOPIC.topic_3, "USVSensorPod/turbidity")
microIoT.microIoT_add_topic(microIoT.TOPIC.topic_4, "USVSensorPod/deploy")
microIoT.microIoT_http_IFTTT("SensorDeploy", "mueyoNQjhWqz9r8pbQfVhqFPEBCBuqinmPDJ5oZYvoE")
radio.setGroup(73)
basic.showIcon(IconNames.Heart)
basic.clearScreen()
14 changes: 14 additions & 0 deletions USV/USV-user.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// https://makecode.microbit.org/S59727-14370-08773-69640

input.onButtonPressed(Button.A, function () {
USV.deployDirection(USV.SensorDeploy.down, 1)
basic.pause(100)
USV.deployDirection(USV.SensorDeploy.up, 1)
})
input.onButtonPressed(Button.B, function () {
USV.USV_Motor(USV.Motors.Both, USV.Speed.ForwardSlow, 4)
})
radio.setGroup(73)
basic.showIcon(IconNames.Happy)


45 changes: 45 additions & 0 deletions docs/MQTT-Design-Pattern.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,48 @@ This section will guide you through the design pattern used to recieve live data
<div style="text-align: center;">
<img src="../img/mqtt-design.png"/>
</div>


# USV User

The USV User script is the only script that can be changed by the User.

It uses the USV's Microbit library to code Missions using the USV and the Sensor Pod

# USV-Lir

The USV is loaded with the [USV-OnBoard.ts](https://github.com/Adam0Brien/USV-LIR-Microbit-Abstraction/blob/main/USV/USV-OnBoard.ts) script as well as the [Sensor-Deploy-Mech.ts](https://github.com/Adam0Brien/USV-LIR-Microbit-Abstraction/blob/main/USV/Sensor-Deployment-Mech.ts) script

These scripts control the USV's basic functionality such as its motor control and sensor deployment, as well as its autonamous drive features.

# Sensor Pod
The sensor pod itself is loaded with [Sensor-Pod-Comms.ts](https://github.com/Adam0Brien/USV-LIR-Microbit-Abstraction/blob/main/USV/Sensor-Pod-Comms.ts).

This script gives the Sensor pod two states it can be in:
- State 0 (Not Sumberged)
- State 1 (Submerged)

Currently the Sensor Pod listens over the radio network for a sensor deploy command from the USV User microbit, this is how the sensor pod knows if it has been sumberged or if it is still above water

- When the Sensor pod is Submerged it takes readings of all its sensors and stores the information to an ArrayList for later use.

- When the Sensor Pod is Not Sumberged it loops through each ArrayList and sends the value over the radio network and then deletes that value in the ArrayList to avoid duplicates.


# Cloud Board

The Cloud Boards main function is to listen to the Radio network for any sensor data, When it recieves data from the sensor pod it posts that data to the [Beebotte](beebotte.com) MQTT Broker which can then be viewed on either Beebotte.com or through an MQTT App.

The MQTT app can then be configured to recieve data from the pre-configured Beebotte Topics,

There has also been an additional topic added that works as a trigger for a Sensor pod deployment which is located in the "Sensor Deploy" button


<div style="text-align: center;">
<img src="../img/MQTT-App-Dashboard.jpeg"/>
</div>

Once a sensor deployment is made Via the [MQTT App](https://snrlab.in/) it triggers an IFTTT Notification that tells the user the sensor pod has been deployed and what values have come back from the deployment
<div style="text-align: center;">
<img src="../img/IFTTT_Notif.jpeg"/>
</div>
Binary file added img/IFTTT_Notif.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/MQTT-App-Dashboard.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 1c22b35

Please sign in to comment.