Bird
0
0

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?

hard🚀 Application Q15 of 15
Raspberry Pi - Data Logging and Databases
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?
Aclient.write_points([ {'measurement': 'temperature', 'tags': {'room': 'living'}, 'fields': {'value': 20}}, {'measurement': 'temperature', 'tags': {'room': 'bedroom'}, 'fields': {'value': 22}} ])
Bclient.write_points({ 'measurement': 'temperature', 'tags': {'room': ['living', 'bedroom']}, 'fields': {'value': [20, 22]} })
Cclient.write_points([ {'measurement': 'temperature', 'tags': {'room': 'living', 'bedroom'}, 'fields': {'value': 20, 22}} ])
Dclient.write_points('temperature', tags={'room': ['living', 'bedroom']}, fields={'value': [20, 22]})
Step-by-Step Solution
Solution:
  1. 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.
  2. 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.
  3. Final Answer:

    client.write_points([ {'measurement': 'temperature', 'tags': {'room': 'living'}, 'fields': {'value': 20}}, {'measurement': 'temperature', 'tags': {'room': 'bedroom'}, 'fields': {'value': 22}} ]) -> Option A
  4. Quick Check:

    List of dicts for multiple points [OK]
Quick Trick: Send multiple points as list of dicts with tags and fields [OK]
Common Mistakes:
MISTAKES
  • Passing lists inside tags or fields instead of separate points
  • Incorrect method parameters
  • Combining tags incorrectly in one dict

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes