InfluxDB is a database designed to store and query time-series data, which means data points collected over time like temperature or sensor readings.
Click to reveal answer
beginner
How does InfluxDB organize data?
InfluxDB organizes data into measurements (like tables), tags (key-value pairs for indexing), fields (actual data values), and timestamps (when data was recorded).
Click to reveal answer
intermediate
Why is InfluxDB good for Raspberry Pi projects?
Because it is lightweight and efficient, InfluxDB can run on Raspberry Pi to collect and analyze sensor data over time without needing heavy resources.
Click to reveal answer
beginner
What is a 'measurement' in InfluxDB?
A measurement is like a table in a traditional database. It groups related time-series data points, such as 'temperature' or 'humidity'.
Click to reveal answer
intermediate
How do you write data points to InfluxDB on Raspberry Pi?
You send data points with a timestamp, measurement name, tags, and fields using HTTP API or client libraries, often in a line protocol format.
Click to reveal answer
What type of data is InfluxDB designed to store?
ABinary files
BRelational data
CTime-series data
DImages
✗ Incorrect
InfluxDB is specialized for time-series data, which is data collected over time.
Which part of InfluxDB stores the actual data values?
ATimestamps
BTags
CMeasurements
DFields
✗ Incorrect
Fields hold the actual data values like temperature or humidity readings.
What does a 'tag' in InfluxDB do?
AIndexes data for faster queries
BStores the timestamp
CHolds the main data value
DDefines the database name
✗ Incorrect
Tags are key-value pairs used to index data and speed up queries.
Why is InfluxDB suitable for Raspberry Pi?
AIt is lightweight and efficient
BIt requires a lot of memory
CIt only works on big servers
DIt stores images
✗ Incorrect
InfluxDB is lightweight, making it good for small devices like Raspberry Pi.
How do you usually send data to InfluxDB?
AUsing FTP
BUsing HTTP API or client libraries
CBy email
DThrough a USB drive
✗ Incorrect
Data is sent to InfluxDB using HTTP API or client libraries in a specific format.
Explain how InfluxDB stores and organizes time-series data.
Think about how a table is structured and what extra parts InfluxDB adds for time.
You got /5 concepts.
Describe why InfluxDB is a good choice for collecting sensor data on a Raspberry Pi.
Consider the device's limitations and the type of data collected.
You got /5 concepts.
Practice
(1/5)
1. What is the main purpose of InfluxDB when used with a Raspberry Pi?
easy
A. To run a web server for hosting websites
B. To control GPIO pins directly
C. To compile Python programs
D. To store and manage time-series data like sensor readings
Solution
Step 1: Understand InfluxDB's role
InfluxDB is designed to store time-series data, which means data points collected over time, such as sensor readings.
Step 2: Compare with other options
Running a web server, compiling Python, or controlling GPIO pins are not the main functions of InfluxDB.
Final Answer:
To store and manage time-series data like sensor readings -> Option D
Quick Check:
InfluxDB = time-series data storage [OK]
Hint: InfluxDB is for time-stamped data storage [OK]
Common Mistakes:
Confusing InfluxDB with web servers
Thinking InfluxDB compiles code
Assuming InfluxDB controls hardware pins
2. Which Python code snippet correctly writes a data point to InfluxDB on a Raspberry Pi?
easy
A. client.write_point('temperature', tags={'room':'kitchen'}, fields={'value':22.5})
B. client.write_points([{'measurement':'temperature','tags':{'room':'kitchen'},'fields':{'value':22.5}}])
C. client.write('temperature', {'room':'kitchen'}, 22.5)
D. client.insert_point('temperature', {'room':'kitchen'}, {'value':22.5})
Solution
Step 1: Recall correct method name and parameters
The InfluxDB Python client uses the method write_points to write data points, and it expects a list of dictionaries with keys 'measurement', 'tags', and 'fields'.
Step 2: Check each option
client.write_points([{'measurement':'temperature','tags':{'room':'kitchen'},'fields':{'value':22.5}}]) matches the correct method and data structure. Options B, C, and D use incorrect method names or parameter formats.
Final Answer:
client.write_points([{'measurement':'temperature','tags':{'room':'kitchen'},'fields':{'value':22.5}}]) -> Option B
Quick Check:
Use write_points with list of dicts [OK]
Hint: Use write_points with list of dicts for data [OK]
Common Mistakes:
Using wrong method names like write_point or insert_point
Passing dict instead of list of dicts
Incorrect parameter structure
3. Given this Python code on Raspberry Pi using InfluxDB client:
data = [{"measurement": "humidity", "tags": {"room": "bedroom"}, "fields": {"value": 45}}]
client.write_points(data)
result = client.query('SELECT * FROM humidity WHERE room = \'bedroom\'')
print(list(result.get_points()))
What will be the output?
medium
A. SyntaxError
B. []
C. [{'time': '...', 'room': 'bedroom', 'value': 45}]
D. None
Solution
Step 1: Understand data insertion
The code writes one data point with measurement 'humidity', tag 'room'='bedroom', and field 'value'=45. This data is stored in InfluxDB.
Step 2: Query and print results
The query selects all points from 'humidity' where 'room'='bedroom'. Since the data was just inserted, the query returns that point. Printing the list of points shows a list with one dictionary containing time, room, and value keys.
Final Answer:
[{'time': '...', 'room': 'bedroom', 'value': 45}] -> Option C
Quick Check:
Inserted data queried returns list with one point [OK]
Hint: Inserted points appear in query results as dicts [OK]
Common Mistakes:
Expecting empty list if data was inserted
Confusing syntax error with query result
Assuming None is returned from query
4. This Python code snippet on Raspberry Pi tries to write data to InfluxDB but fails:
A. Error: write_points expects a list of points; fix by wrapping data in a list
B. Error: 'fields' key missing; fix by adding 'fields' key
C. Error: 'measurement' must be a string; fix by converting to string
D. No error; code works fine
Solution
Step 1: Identify method parameter requirements
The write_points method requires a list of data points, even if only one point is written.
Step 2: Analyze given code
The code passes a single dictionary instead of a list containing that dictionary, causing an error.
Final Answer:
Error: write_points expects a list of points; fix by wrapping data in a list -> Option A
Quick Check:
write_points needs list of dicts [OK]
Hint: Always pass a list to write_points even for one point [OK]
Common Mistakes:
Passing dict instead of list to write_points
Missing 'fields' key in data point
Assuming no error occurs
5. You want to store temperature readings from multiple rooms on a Raspberry Pi using InfluxDB. Which Python code correctly writes two points with tags and fields in one call?
D. client.write_points('temperature', tags={'room': ['living', 'bedroom']}, fields={'value': [20, 22]})
Solution
Step 1: Understand data structure for multiple points
Each data point must be a dictionary with 'measurement', 'tags', and 'fields'. Multiple points are passed as a list of such dictionaries.
Step 2: Evaluate options
client.write_points([
{'measurement': 'temperature', 'tags': {'room': 'living'}, 'fields': {'value': 20}},
{'measurement': 'temperature', 'tags': {'room': 'bedroom'}, 'fields': {'value': 22}}
]) correctly uses a list of two dictionaries, each with proper tags and fields. Options A, B, and C misuse data structures or method parameters.