Skip to content

Commit b9f2d93

Browse files
author
Jim Bennett
authored
Fixing some code and adding names (#110)
* Adding content * Update en.json * Update README.md * Update TRANSLATIONS.md * Adding lesson tempolates * Fixing code files with each others code in * Update README.md * Adding lesson 16 * Adding virtual camera * Adding Wio Terminal camera capture * Adding wio terminal code * Adding SBC classification to lesson 16 * Adding challenge, review and assignment * Adding images and using new Azure icons * Update README.md * Update iot-reference-architecture.png * Adding structure for JulyOT links * Removing icons * Sketchnotes! * Create lesson-1.png * Starting on lesson 18 * Updated sketch * Adding virtual distance sensor * Adding Wio Terminal image classification * Update README.md * Adding structure for project 6 and wio terminal distance sensor * Adding some of the smart timer stuff * Updating sketchnotes * Adding virtual device speech to text * Adding chapter 21 * Language tweaks * Lesson 22 stuff * Update en.json * Bumping seeed libraries * Adding functions lab to lesson 22 * Almost done with LUIS * Update README.md * Reverting sunlight sensor change Fixes #88 * Structure * Adding speech to text lab for Pi * Adding virtual device text to speech lab * Finishing lesson 23 * Clarifying privacy Fixes #99 * Update README.md * Update hardware.md * Update README.md * Fixing some code samples that were wrong
1 parent fa3d078 commit b9f2d93

File tree

13 files changed

+89
-101
lines changed

13 files changed

+89
-101
lines changed

2-farm/lessons/5-migrate-application-to-the-cloud/README.md

+17-17
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,23 @@ The Azure Functions CLI can be used to create a new Functions app.
192192

193193
> ⚠️ If you get a firewall notification, grant access as the `func` application needs to be able to read and write to your network.
194194

195+
> ⚠️ If you are using macOS, there may be warnings in the output:
196+
>
197+
> ```output
198+
> (.venv) ➜ soil-moisture-trigger func start
199+
> Found Python version 3.9.1 (python3).
200+
>
201+
> Azure Functions Core Tools
202+
> Core Tools Version: 3.0.3442 Commit hash: 6bfab24b2743f8421475d996402c398d2fe4a9e0 (64-bit)
203+
> Function Runtime Version: 3.0.15417.0
204+
>
205+
> [2021-06-16T08:18:28.315Z] Cannot create directory for shared memory usage: /dev/shm/AzureFunctions
206+
> [2021-06-16T08:18:28.316Z] System.IO.FileSystem: Access to the path '/dev/shm/AzureFunctions' is denied. Operation not permitted.
207+
> [2021-06-16T08:18:30.361Z] No job functions found.
208+
> ```
209+
>
210+
> You can ignore these as long as the Functions app starts correctly and lists the running functions. As mentioned in [this question on the Microsoft Docs Q&A](https://docs.microsoft.com/answers/questions/396617/azure-functions-core-tools-error-osx-devshmazurefu.html?WT.mc_id=academic-17441-jabenn) it can be ignored.
211+
195212
1. Stop the Functions app by pressing `ctrl+c`.
196213

197214
1. Open the current folder in VS Code, either by opening VS Code, then opening this folder, or by running the following:
@@ -213,23 +230,6 @@ The Azure Functions CLI can be used to create a new Functions app.
213230

214231
1. Make sure the Python virtual environment is running in the VS Code terminal. Terminate it and restart it if necessary.
215232

216-
1. There may be warnings in the output:
217-
218-
```output
219-
(.venv) ➜ soil-moisture-trigger func start
220-
Found Python version 3.9.1 (python3).
221-
222-
Azure Functions Core Tools
223-
Core Tools Version: 3.0.3442 Commit hash: 6bfab24b2743f8421475d996402c398d2fe4a9e0 (64-bit)
224-
Function Runtime Version: 3.0.15417.0
225-
226-
[2021-06-16T08:18:28.315Z] Cannot create directory for shared memory usage: /dev/shm/AzureFunctions
227-
[2021-06-16T08:18:28.316Z] System.IO.FileSystem: Access to the path '/dev/shm/AzureFunctions' is denied. Operation not permitted.
228-
[2021-06-16T08:18:30.361Z] No job functions found.
229-
```
230-
231-
but don't worry about them as long as the Functions app starts correctly and lists the running functions. As mentioned in this question on the [Docs Q&A](https://docs.microsoft.com/answers/questions/396617/azure-functions-core-tools-error-osx-devshmazurefu.html?WT.mc_id=academic-17441-jabenn) it can be ignored.
232-
233233
## Create an IoT Hub event trigger
234234

235235
The Functions app is the shell of your serverless code. To respond to IoT hub events, you can add an IoT Hub trigger to this app. This trigger needs to connect to the stream of messages that are sent to the IoT Hub and respond to them. To get this stream of messages, your trigger needs to connect to the IoT Hubs *event hub compatible endpoint*.

3-transport/lessons/1-location-tracking/code-gps-decode/pi/gps-sensor/app.py

+3-15
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,12 @@
22
import serial
33
import pynmea2
44
import json
5-
from azure.iot.device import IoTHubDeviceClient, Message
6-
7-
connection_string = '<connection_string>'
85

96
serial = serial.Serial('/dev/ttyAMA0', 9600, timeout=1)
107
serial.reset_input_buffer()
118
serial.flush()
129

13-
device_client = IoTHubDeviceClient.create_from_connection_string(connection_string)
14-
15-
print('Connecting')
16-
device_client.connect()
17-
print('Connected')
18-
19-
def printGPSData(line):
10+
def print_gps_data(line):
2011
msg = pynmea2.parse(line)
2112
if msg.sentence_type == 'GGA':
2213
lat = pynmea2.dm_to_sd(msg.lat)
@@ -28,16 +19,13 @@ def printGPSData(line):
2819
if msg.lon_dir == 'W':
2920
lon = lon * -1
3021

31-
message_json = { "gps" : { "lat":lat, "lon":lon } }
32-
print("Sending telemetry", message_json)
33-
message = Message(json.dumps(message_json))
34-
device_client.send_message(message)
22+
print(f'{lat},{lon} - from {msg.num_sats} satellites')
3523

3624
while True:
3725
line = serial.readline().decode('utf-8')
3826

3927
while len(line) > 0:
40-
printGPSData(line)
28+
print_gps_data(line)
4129
line = serial.readline().decode('utf-8')
4230

4331
time.sleep(1)

3-transport/lessons/1-location-tracking/code-gps-decode/virtual-device/gps-sensor/app.py

+2-12
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,11 @@
55
import counterfit_shims_serial
66
import pynmea2
77
import json
8-
from azure.iot.device import IoTHubDeviceClient, Message
98

109
connection_string = '<connection_string>'
1110

1211
serial = counterfit_shims_serial.Serial('/dev/ttyAMA0')
1312

14-
device_client = IoTHubDeviceClient.create_from_connection_string(connection_string)
15-
16-
print('Connecting')
17-
device_client.connect()
18-
print('Connected')
19-
2013
def send_gps_data(line):
2114
msg = pynmea2.parse(line)
2215
if msg.sentence_type == 'GGA':
@@ -29,10 +22,7 @@ def send_gps_data(line):
2922
if msg.lon_dir == 'W':
3023
lon = lon * -1
3124

32-
message_json = { "gps" : { "lat":lat, "lon":lon } }
33-
print("Sending telemetry", message_json)
34-
message = Message(json.dumps(message_json))
35-
device_client.send_message(message)
25+
print(f'{lat},{lon} - from {msg.num_sats} satellites')
3626

3727
while True:
3828
line = serial.readline().decode('utf-8')
@@ -41,4 +31,4 @@ def send_gps_data(line):
4131
send_gps_data(line)
4232
line = serial.readline().decode('utf-8')
4333

44-
time.sleep(60)
34+
time.sleep(1)

3-transport/lessons/1-location-tracking/code-gps/pi/gps-sensor/app.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
serial.reset_input_buffer()
66
serial.flush()
77

8-
def printGPSData():
8+
def print_gps_data():
99
print(line.rstrip())
1010

1111
while True:
1212
line = serial.readline().decode('utf-8')
1313

1414
while len(line) > 0:
15-
printGPSData()
15+
print_gps_data()
1616
line = serial.readline().decode('utf-8')
1717

1818
time.sleep(1)

3-transport/lessons/1-location-tracking/code-gps/virtual-device/gps-sensor/app.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66

77
serial = counterfit_shims_serial.Serial('/dev/ttyAMA0')
88

9-
def printGPSData(line):
9+
def print_gps_data(line):
1010
print(line.rstrip())
1111

1212
while True:
1313
line = serial.readline().decode('utf-8')
1414

1515
while len(line) > 0:
16-
printGPSData(line)
16+
print_gps_data(line)
1717
line = serial.readline().decode('utf-8')
1818

1919
time.sleep(1)

3-transport/lessons/1-location-tracking/pi-gps-sensor.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -118,24 +118,24 @@ Program the device.
118118
serial.reset_input_buffer()
119119
serial.flush()
120120
121-
def printGPSData(line):
121+
def print_gps_data(line):
122122
print(line.rstrip())
123123
124124
while True:
125125
line = serial.readline().decode('utf-8')
126126
127127
while len(line) > 0:
128-
printGPSData(line)
128+
print_gps_data(line)
129129
line = serial.readline().decode('utf-8')
130130
131131
time.sleep(1)
132132
```
133133
134134
This code imports the `serial` module from the `pyserial` Pip package. It then connects to the `/dev/ttyAMA0` serial port - this is the address of the serial port that the Grove Pi Base Hat uses for its UART port. It then clears any existing data from this serial connection.
135135
136-
Next a function called `printGPSData` is defined that prints out the line passed to it to the console.
136+
Next a function called `print_gps_data` is defined that prints out the line passed to it to the console.
137137
138-
Next the code loops forever, reading as many lines of text as it can from the serial port in each loop. It calls the `printGPSData` function for each line.
138+
Next the code loops forever, reading as many lines of text as it can from the serial port in each loop. It calls the `print_gps_data` function for each line.
139139
140140
After all the data has been read, the loop sleeps for 1 second, then tries again.
141141

3-transport/lessons/1-location-tracking/single-board-computer-gps-decode.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Program the device to decode the GPS data.
2424
import pynmea2
2525
```
2626

27-
1. Replace the contents of the `printGPSData` function with the following:
27+
1. Replace the contents of the `print_gps_data` function with the following:
2828

2929
```python
3030
msg = pynmea2.parse(line)

3-transport/lessons/1-location-tracking/virtual-device-gps-sensor.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -77,22 +77,22 @@ Program the GPS sensor app.
7777
1. Add the following code below this to read from the serial port and print the values to the console:
7878

7979
```python
80-
def printGPSData(line):
80+
def print_gps_data(line):
8181
print(line.rstrip())
8282
8383
while True:
8484
line = serial.readline().decode('utf-8')
8585
8686
while len(line) > 0:
87-
printGPSData(line)
87+
print_gps_data(line)
8888
line = serial.readline().decode('utf-8')
8989
9090
time.sleep(1)
9191
```
9292
93-
A function called `printGPSData` is defined that prints out the line passed to it to the console.
93+
A function called `print_gps_data` is defined that prints out the line passed to it to the console.
9494
95-
Next the code loops forever, reading as many lines of text as it can from the serial port in each loop. It calls the `printGPSData` function for each line.
95+
Next the code loops forever, reading as many lines of text as it can from the serial port in each loop. It calls the `print_gps_data` function for each line.
9696
9797
After all the data has been read, the loop sleeps for 1 second, then tries again.
9898
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,43 @@
11
import time
2-
from grove.adc import ADC
3-
from grove.grove_relay import GroveRelay
2+
import serial
3+
import pynmea2
44
import json
5-
from azure.iot.device import IoTHubDeviceClient, Message, MethodResponse
5+
from azure.iot.device import IoTHubDeviceClient, Message
66

77
connection_string = '<connection_string>'
88

9-
adc = ADC()
10-
relay = GroveRelay(5)
9+
serial = serial.Serial('/dev/ttyAMA0', 9600, timeout=1)
10+
serial.reset_input_buffer()
11+
serial.flush()
1112

1213
device_client = IoTHubDeviceClient.create_from_connection_string(connection_string)
1314

1415
print('Connecting')
1516
device_client.connect()
1617
print('Connected')
1718

18-
def handle_method_request(request):
19-
print("Direct method received - ", request.name)
20-
21-
if request.name == "relay_on":
22-
relay.on()
23-
elif request.name == "relay_off":
24-
relay.off()
19+
def print_gps_data(line):
20+
msg = pynmea2.parse(line)
21+
if msg.sentence_type == 'GGA':
22+
lat = pynmea2.dm_to_sd(msg.lat)
23+
lon = pynmea2.dm_to_sd(msg.lon)
2524

26-
method_response = MethodResponse.create_from_method_request(request, 200)
27-
device_client.send_method_response(method_response)
25+
if msg.lat_dir == 'S':
26+
lat = lat * -1
2827

29-
device_client.on_method_request_received = handle_method_request
28+
if msg.lon_dir == 'W':
29+
lon = lon * -1
30+
31+
message_json = { "gps" : { "lat":lat, "lon":lon } }
32+
print("Sending telemetry", message_json)
33+
message = Message(json.dumps(message_json))
34+
device_client.send_message(message)
3035

3136
while True:
32-
soil_moisture = adc.read(0)
33-
print("Soil moisture:", soil_moisture)
37+
line = serial.readline().decode('utf-8')
3438

35-
message = Message(json.dumps({ 'soil_moisture': soil_moisture }))
36-
device_client.send_message(message)
39+
while len(line) > 0:
40+
print_gps_data(line)
41+
line = serial.readline().decode('utf-8')
3742

38-
time.sleep(10)
43+
time.sleep(60)

3-transport/lessons/2-store-location-data/code/virtual-device/gps-sensor/app.py

+23-20
Original file line numberDiff line numberDiff line change
@@ -2,40 +2,43 @@
22
CounterFitConnection.init('127.0.0.1', 5000)
33

44
import time
5-
from counterfit_shims_grove.adc import ADC
6-
from counterfit_shims_grove.grove_relay import GroveRelay
5+
import counterfit_shims_serial
6+
import pynmea2
77
import json
8-
from azure.iot.device import IoTHubDeviceClient, Message, MethodResponse
8+
from azure.iot.device import IoTHubDeviceClient, Message
99

1010
connection_string = '<connection_string>'
1111

12-
adc = ADC()
13-
relay = GroveRelay(5)
12+
serial = counterfit_shims_serial.Serial('/dev/ttyAMA0')
1413

1514
device_client = IoTHubDeviceClient.create_from_connection_string(connection_string)
1615

1716
print('Connecting')
1817
device_client.connect()
1918
print('Connected')
2019

21-
def handle_method_request(request):
22-
print("Direct method received - ", request.name)
23-
24-
if request.name == "relay_on":
25-
relay.on()
26-
elif request.name == "relay_off":
27-
relay.off()
20+
def send_gps_data(line):
21+
msg = pynmea2.parse(line)
22+
if msg.sentence_type == 'GGA':
23+
lat = pynmea2.dm_to_sd(msg.lat)
24+
lon = pynmea2.dm_to_sd(msg.lon)
2825

29-
method_response = MethodResponse.create_from_method_request(request, 200)
30-
device_client.send_method_response(method_response)
26+
if msg.lat_dir == 'S':
27+
lat = lat * -1
3128

32-
device_client.on_method_request_received = handle_method_request
29+
if msg.lon_dir == 'W':
30+
lon = lon * -1
31+
32+
message_json = { "gps" : { "lat":lat, "lon":lon } }
33+
print("Sending telemetry", message_json)
34+
message = Message(json.dumps(message_json))
35+
device_client.send_message(message)
3336

3437
while True:
35-
soil_moisture = adc.read(0)
36-
print("Soil moisture:", soil_moisture)
38+
line = serial.readline().decode('utf-8')
3739

38-
message = Message(json.dumps({ 'soil_moisture': soil_moisture }))
39-
device_client.send_message(message)
40+
while len(line) > 0:
41+
send_gps_data(line)
42+
line = serial.readline().decode('utf-8')
4043

41-
time.sleep(10)
44+
time.sleep(60)

6-consumer/lessons/4-multiple-language-support/README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
Add a sketchnote if possible/appropriate
44

5-
![Embed a video here if available](video-url)
5+
This video gives an overview of the Azure speech services, covering speech to text and text to speech from earlier lessons, as well as translating speech, a topic covered in this lesson:
6+
7+
[![Recognizing speech with a few lines of Python from Microsoft Build 2020](https://img.youtube.com/vi/h6xbpMPSGEA/0.jpg)](https://www.youtube.com/watch?v=h6xbpMPSGEA)
68

79
## Pre-lecture quiz
810

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ The projects cover the journey of food from farm to table. This includes farming
2020

2121
![A road map for the course showing 24 lessons covering intro, farming, transport, processing, retail and cooking](sketchnotes/Roadmap.png)
2222

23-
**Hearty thanks to our authors [Jen Fox](https://github.com/jenfoxbot), [Jen Looper](https://github.com/jlooper), [Jim Bennett](https://github.com/jimbobbennett), and our sketchnote artist [Nitya Narasimhan](https://github.com/nitya)**
23+
**Hearty thanks to our authors [Jen Fox](https://github.com/jenfoxbot), [Jen Looper](https://github.com/jlooper), [Jim Bennett](https://github.com/jimbobbennett), and our sketchnote artist [Nitya Narasimhan](https://github.com/nitya).**
2424

25-
**Thanks as well to our team of [Microsoft Learn Student Ambassadors](https://studentambassadors.microsoft.com?WT.mc_id=academic-17441-jabenn) who have been reviewing and translating this curriculum - [Manvi Jha](https://github.com/Severus-Matthew), [Mireille Tan](https://www.linkedin.com/in/mireille-tan-a4834819a/), [Mohammad Iftekher (Iftu) Ebne Jalal](https://github.com/Iftu119), [Priyanshu Srivastav](https://www.linkedin.com/in/priyanshu-srivastav-b067241ba), and [Zina Kamel](https://www.linkedin.com/in/zina-kamel/)**
25+
**Thanks as well to our team of [Microsoft Learn Student Ambassadors](https://studentambassadors.microsoft.com?WT.mc_id=academic-17441-jabenn) who have been reviewing and translating this curriculum - [Bhavesh Suneja](https://github.com/EliteWarrior315), [Lateefah Bello](https://www.linkedin.com/in/lateefah-bello/), [Manvi Jha](https://github.com/Severus-Matthew), [Mireille Tan](https://www.linkedin.com/in/mireille-tan-a4834819a/), [Mohammad Iftekher (Iftu) Ebne Jalal](https://github.com/Iftu119), [Priyanshu Srivastav](https://www.linkedin.com/in/priyanshu-srivastav-b067241ba), and [Zina Kamel](https://www.linkedin.com/in/zina-kamel/).**
2626

2727
> **Teachers**, we have [included some suggestions](for-teachers.md) on how to use this curriculum. If you would like to create your own lessons, we have also included a [lesson template](lesson-template/README.md).
2828

hardware.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ All the device code for Raspberry Pi is in Python. To complete all the assignmen
4646

4747
These are specific to using the Raspberry Pi, and are not relevant to using the Arduino device.
4848

49-
* [Grove Pi base hat](https://wiki.seeedstudio.com/Grove_Base_Hat_for_Raspberry_Pi)
49+
* [Grove Pi base hat](https://www.seeedstudio.com/Grove-Base-Hat-for-Raspberry-Pi.html)
5050
* [Raspberry Pi Camera module](https://www.raspberrypi.org/products/camera-module-v2/)
5151
* Microphone and speaker:
5252

0 commit comments

Comments
 (0)