📖 Scenario: You are working with a LoRaWAN device configuration. LoRaWAN uses spreading factors (SF) to control data rate and range. Higher SF means longer range but slower data rate. You want to understand how changing the spreading factor affects the data rate.
🎯 Goal: Build a simple program that stores spreading factors and their corresponding data rates, then filter and display only those spreading factors that have data rates above a certain threshold.
📋 What You'll Learn
Create a dictionary called sf_data_rates with exact spreading factors as keys and their data rates (in kbps) as values
Create a variable called min_data_rate with a value of 5
Use a dictionary comprehension to create a new dictionary called filtered_sf containing only spreading factors with data rates greater than min_data_rate
Print the filtered_sf dictionary
💡 Why This Matters
🌍 Real World
LoRaWAN devices use spreading factors to balance range and data speed. Understanding this helps optimize device settings for battery life and communication reliability.
💼 Career
Network engineers and IoT developers often configure LoRaWAN parameters to meet specific coverage and data rate needs in real deployments.
Progress0 / 4 steps
1
Create spreading factor data rates dictionary
Create a dictionary called sf_data_rates with these exact entries: 7: 5.47, 8: 3.13, 9: 1.76, 10: 0.98, 11: 0.54, 12: 0.29
IOT Protocols
Hint
Use curly braces to create a dictionary with spreading factors as keys and data rates as values.
2
Set minimum data rate threshold
Create a variable called min_data_rate and set it to 5
IOT Protocols
Hint
Just assign the number 5 to the variable named min_data_rate.
3
Filter spreading factors by data rate
Use a dictionary comprehension to create a new dictionary called filtered_sf that contains only the spreading factors from sf_data_rates where the data rate is greater than min_data_rate
IOT Protocols
Hint
Use {key: value for key, value in dict.items() if condition} syntax to filter the dictionary.
4
Display filtered spreading factors
Print the filtered_sf dictionary
IOT Protocols
Hint
Use print(filtered_sf) to show the filtered dictionary.
Practice
(1/5)
1. What happens to the data rate when the spreading factor is increased in an IoT communication?
easy
A. The data rate stays the same regardless of spreading factor.
B. The data rate increases, making transmission faster.
C. The data rate decreases, making transmission slower.
D. The data rate becomes unpredictable and varies randomly.
Solution
Step 1: Understand spreading factor effect
Increasing the spreading factor spreads the signal over more time, which slows down the data transmission.
Step 2: Relate spreading factor to data rate
Since the signal takes longer to send, the data rate decreases as spreading factor increases.
Final Answer:
The data rate decreases, making transmission slower. -> Option C
Quick Check:
Higher spreading factor = slower data rate [OK]
Hint: Higher spreading factor means slower data rate [OK]
Common Mistakes:
Thinking higher spreading factor increases speed
Assuming data rate is unaffected by spreading factor
Confusing spreading factor with signal strength
2. Which of the following is the correct way to set a spreading factor of 10 in a LoRa device configuration command?
easy
A. setSF(10)
B. set_spreading_factor = 10
C. configureSF(10)
D. setSpreadingFactor(10)
Solution
Step 1: Identify common LoRa configuration syntax
LoRa libraries often use camelCase method names like setSpreadingFactor() to set parameters.
Step 2: Match the correct syntax
Among the options, setSpreadingFactor(10) is the correct method call to set spreading factor to 10.
Final Answer:
setSpreadingFactor(10) -> Option D
Quick Check:
Correct method name uses camelCase [OK]
Hint: Look for camelCase method names in device APIs [OK]
Common Mistakes:
Using assignment instead of method call
Incorrect method naming style
Confusing parameter setting with variable assignment
3. Consider this pseudocode for a LoRa device:
sf = 7
if sf > 9:
data_rate = "slow"
else:
data_rate = "fast"
print(data_rate)
What will be the output?
medium
A. fast
B. slow
C. sf
D. Error
Solution
Step 1: Evaluate the condition with sf = 7
Since 7 is not greater than 9, the else block executes.
Step 2: Determine the assigned data_rate
The else block sets data_rate to "fast" and prints it.
Final Answer:
fast -> Option A
Quick Check:
sf=7 <=9 means data_rate = fast [OK]
Hint: Check condition carefully for > or <= [OK]
Common Mistakes:
Assuming sf=7 is greater than 9
Confusing else and if blocks
Expecting variable name instead of value output
4. A developer wrote this code snippet to set data rate based on spreading factor: