You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+66-19Lines changed: 66 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,11 +7,8 @@
7
7
8
8
Cadet is the web application powering Source Academy.
9
9
10
-
*`master` is the main development branch, and may be broken, buggy, unstable,
11
-
etc. It may not work with the frontend, if there are frontend changes that
12
-
have not yet been merged.
13
-
*`stable` is the stable branch and should work with the stable branch of the
14
-
frontend. Note that `stable` may not have stable history!
10
+
-`master` is the main development branch, and may be broken, buggy, unstable, etc. It may not work with the frontend, if there are frontend changes that have not yet been merged.
11
+
-`stable` is the stable branch and should work with the stable branch of the frontend. Note that `stable` may not have stable history!
15
12
16
13
## Developer setup
17
14
@@ -21,9 +18,7 @@ Cadet is the web application powering Source Academy.
21
18
2. Erlang/OTP 23.2.1
22
19
3. PostgreSQL 13 or 14
23
20
24
-
It is probably okay to use a different version of PostgreSQL or Erlang/OTP, but
25
-
using a different version of Elixir may result in differences in e.g. `mix
26
-
format`.
21
+
It is probably okay to use a different version of PostgreSQL or Erlang/OTP, but using a different version of Elixir may result in differences in e.g. `mix format`.
27
22
28
23
### Setting up your local development environment
29
24
@@ -34,9 +29,7 @@ format`.
34
29
$ vim config/dev.secrets.exs
35
30
```
36
31
37
-
- To use NUSNET authentication, specify the NUS ADFS OAuth2 URL. (Ask for it.)
38
-
Note that the frontend will supply the ADFS client ID and redirect URL (so
39
-
you will need that too, but not here).
32
+
- To use NUSNET authentication, specify the NUS ADFS OAuth2 URL. (Ask for it.) Note that the frontend will supply the ADFS client ID and redirect URL (so you will need that too, but not here).
40
33
41
34
2. Install Elixir dependencies
42
35
@@ -56,14 +49,69 @@ format`.
56
49
$ mix phx.server
57
50
```
58
51
59
-
5. You may now make API calls to the server locally via `localhost:4000`. The
60
-
API documentation can also be accessed at http://localhost:4000/swagger.
52
+
5. You may now make API calls to the server locally via `localhost:4000`. The API documentation can also be accessed at http://localhost:4000/swagger.
61
53
54
+
If you don't need to test MQTT connections for remote execution using [Sling](source-academy/sling), you can stop here. Otherwise, continue to [set up the local development environment with MQTT](#setting-up-a-local-development-environment-with-mqtt-support).
55
+
56
+
### Setting up a local development environment with MQTT support
57
+
58
+
In addition to performing the steps [above](#setting-up-your-local-development-environment), you will need to do the following:
59
+
60
+
1. Set up a local MQTT server.
61
+
One cross-platform solution is Mosquitto. Follow their [instructions](https://mosquitto.org/download/) on how to install it for your system.
62
+
63
+
2. Update Mosquitto configurations
64
+
We will require two listeners on two different ports: one for listening to the WebSockets connection from Source Academy Frontend, and one to listen for the regular MQTT connection from the EV3. Locate your `mosquitto.conf` file, and add the following lines:
65
+
66
+
```conf
67
+
# Default listener
68
+
listener 1883
69
+
protocol mqtt
70
+
allow_anonymous true
71
+
72
+
# MQTT over WebSockets
73
+
listener 9001
74
+
protocol websockets
75
+
allow_anonymous true
76
+
```
77
+
78
+
If necessary, you can change the default port numbers, but it is generally best to stick to the default MQQT/WS ports.
79
+
80
+
3. Restart the Mosquitto service to apply configuration changes
81
+
82
+
4. Manually update `lib/cadet/devices/devices.ex` to use our local MQTT server
83
+
The MQTT endpoints are hardcoded to use AWS. For local development, change (but **do not commit**) the following functions:
84
+
85
+
-`get_device_ws_endpoint` returns the address the frontend should connect to. Take not that the port number should match what you have defined earlier in `mosquitto.conf`. Assuming your backend, frontend and MQTT server are hosted on the same computer, edit the function body as follows:
86
+
87
+
```elixir
88
+
defget_device_ws_endpoint(%Device{id: device_id}, %User{id: user_id}, opts) do
89
+
{:ok,
90
+
%{
91
+
endpoint:"ws://localhost:9001/",
92
+
thing_name:get_thing_name(device_id),
93
+
client_name_prefix:get_ws_client_prefix(user_id)
94
+
}}
95
+
end
96
+
```
97
+
98
+
- `get_endpoint_address` gives the address the EV3 should connect to (under normal operations). The address should be the local IP address of the computer hosting the MQTT server. Again, take note of the port number.
99
+
<details><summary>Sidenote on connecting from the EV3</summary>
100
+
101
+
We will not actually use this return value for anything, so the actual value. We just need to hardcode something to return (and stop the backend from trying to connect to AWS). Also, it is good practice to assume that the value is going to be used anyway:
102
+
</details>
103
+
104
+
```elixir
105
+
defget_endpoint_addressdo
106
+
{:ok, "192.168.139.10:1883"} # This won't actually be used (for now -- see sidenote)
107
+
end
108
+
```
109
+
110
+
Your backend is now all set up for remote execution using a local MQTT server. To see how to configure the EV3 to use a local MQTT server, check out the [EV3-Source](https://github.com/source-academy/ev3-source) repository.
62
111
63
112
### Obtaining `access_token` in dev environment
64
113
65
-
You can obtain an `access_token` JWT for a user with a given role by simply
66
-
running:
114
+
You can obtain an `access_token` JWTfor a user with a given role by simply running:
67
115
68
116
```bash
69
117
$ mix cadet.token <role>
@@ -77,11 +125,9 @@ $ mix help cadet.token
77
125
78
126
### Style Guide
79
127
80
-
We follow this style guide: https://github.com/lexmag/elixir-style-guide and
0 commit comments