Table of Contents
Google Cloud IoT provides a suite of managed services to connect, process, and analyse data from IoT devices at scale. When combined with the Raspberry Pi’s Linux-based flexibility, you get a complete IoT platform capable of handling everything from prototype to production. This guide covers the entire workflow for Indian developers.
Introduction to Google Cloud IoT
While Google Cloud IoT Core (the original device management service) was retired in August 2023, Google continues to offer powerful IoT capabilities through Pub/Sub, Cloud Functions, BigQuery, and partner integrations. The recommended approach now uses MQTT with Cloud Pub/Sub directly, giving you more flexibility and often lower costs.
Key services for IoT on Google Cloud:
- Cloud Pub/Sub: Managed message ingestion (first 10 GB/month free)
- Cloud Functions: Serverless event processing
- BigQuery: Petabyte-scale analytics (first 1 TB queries/month free)
- Looker Studio: Free dashboard and visualisation tool
Why Google Cloud for IoT in India
Google Cloud offers compelling advantages for Indian IoT deployments:
- Mumbai Region (asia-south1): Low-latency data processing within India
- Generous Free Tier: $300 credit for 90 days plus always-free tier for many services
- BigQuery: Unmatched for analysing large sensor datasets — query terabytes in seconds
- TensorFlow Integration: Train ML models on your IoT data using TPU infrastructure
- Firebase: Real-time database and mobile app integration for IoT dashboards
Setting Up Your Raspberry Pi
Prepare your Raspberry Pi for IoT development:
# Update system
sudo apt update && sudo apt upgrade -y
# Install Python dependencies
sudo apt install -y python3-pip python3-venv
python3 -m venv iot-env
source iot-env/bin/activate
# Install Google Cloud libraries
pip install google-cloud-pubsub google-auth paho-mqtt
pip install adafruit-circuitpython-dht adafruit-circuitpython-bme280
# Install gcloud CLI
curl -sSL https://sdk.cloud.google.com | bash
gcloud init
Sensors for Raspberry Pi IoT
Configuring Google Cloud IoT Core
Set up your Google Cloud project for IoT:
- Create a new project in Google Cloud Console
- Enable the Cloud Pub/Sub API
- Create a Pub/Sub topic named
iot-telemetry - Create a subscription for consuming messages
- Create a service account with Pub/Sub Publisher role
- Download the JSON key file and transfer to your Raspberry Pi
Device Registration and Authentication
For secure device authentication, generate an RSA key pair on your Raspberry Pi:
# Generate RSA-256 key pair
openssl genpkey -algorithm RSA -out device_private.pem -pkeyopt rsa_keygen_bits:2048
openssl rsa -in device_private.pem -pubout -out device_public.pem
# Set proper permissions
chmod 600 device_private.pem
Sending Telemetry Data with Python
Here is a complete Python script that reads sensor data and publishes to Google Cloud Pub/Sub:
import json
import time
from datetime import datetime
from google.cloud import pubsub_v1
import board
import adafruit_dht
# Configuration
PROJECT_ID = "your-project-id"
TOPIC_ID = "iot-telemetry"
DEVICE_ID = "rpi-sensor-mumbai-01"
# Initialise sensor (DHT22 on GPIO4)
dht_sensor = adafruit_dht.DHT22(board.D4)
# Initialise Pub/Sub publisher
publisher = pubsub_v1.PublisherClient()
topic_path = publisher.topic_path(PROJECT_ID, TOPIC_ID)
def read_and_publish():
try:
temperature = dht_sensor.temperature
humidity = dht_sensor.humidity
if temperature is None or humidity is None:
print("Sensor read failed, retrying...")
return
payload = {
"device_id": DEVICE_ID,
"temperature_c": round(temperature, 2),
"humidity_pct": round(humidity, 2),
"timestamp": datetime.utcnow().isoformat(),
"location": "Mumbai, India"
}
data = json.dumps(payload).encode("utf-8")
future = publisher.publish(topic_path, data)
print(f"Published: {payload} [msg_id: {future.result()}]")
except Exception as e:
print(f"Error: {e}")
if __name__ == "__main__":
print(f"Starting IoT telemetry for {DEVICE_ID}")
while True:
read_and_publish()
time.sleep(60) # Publish every 60 seconds
Visualising Data with BigQuery and Data Studio
Once data flows into Pub/Sub, route it to BigQuery for analysis:
- Create a BigQuery dataset and table matching your JSON schema
- Set up a Pub/Sub subscription that writes directly to BigQuery (no code needed)
- Query your data:
SELECT AVG(temperature_c), DATE(timestamp) FROM iot_data.telemetry GROUP BY 2 - Connect Looker Studio to BigQuery and build real-time dashboards
The entire pipeline — from Raspberry Pi sensor to visual dashboard — can be set up within the free tier for small projects.
Recommended Product
BME280 Environmental Sensor (Temperature, Humidity, Barometric Pressure)
Frequently Asked Questions
Is Google Cloud IoT Core still available?
Google Cloud IoT Core was retired in August 2023. However, you can build equivalent functionality using Cloud Pub/Sub with MQTT, Cloud Functions, and BigQuery. Many users find this approach more flexible and cost-effective.
How much does Google Cloud cost for IoT in India?
Google Cloud offers $300 free credit for 90 days. The always-free tier includes 10 GB Pub/Sub throughput, 1 TB BigQuery queries, and 2 million Cloud Function invocations per month. A typical hobby project costs nothing.
Can Raspberry Pi handle continuous sensor reading?
Yes. Raspberry Pi runs Linux and can operate 24/7. Use systemd services to ensure your Python script auto-starts on boot and restarts on failure.
What is the latency from India to Google Cloud?
With the Mumbai region (asia-south1), typical latency is 5-15ms from major Indian cities. This is suitable for real-time monitoring applications.
{“@context”: “https://schema.org”, “@type”: “FAQPage”, “mainEntity”: [{“@type”: “Question”, “name”: “Is Google Cloud IoT Core still available?”, “acceptedAnswer”: {“@type”: “Answer”, “text”: “Google Cloud IoT Core was retired in August 2023. However, you can build equivalent functionality using Cloud Pub/Sub with MQTT, Cloud Functions, and BigQuery. Many users find this approach more flexible and cost-effective.”}}, {“@type”: “Question”, “name”: “How much does Google Cloud cost for IoT in India?”, “acceptedAnswer”: {“@type”: “Answer”, “text”: “Google Cloud offers $300 free credit for 90 days. The always-free tier includes 10 GB Pub/Sub throughput, 1 TB BigQuery queries, and 2 million Cloud Function invocations per month. A typical hobby project costs nothing.”}}, {“@type”: “Question”, “name”: “Can Raspberry Pi handle continuous sensor reading?”, “acceptedAnswer”: {“@type”: “Answer”, “text”: “Yes. Raspberry Pi runs Linux and can operate 24/7. Use systemd services to ensure your Python script auto-starts on boot and restarts on failure.”}}, {“@type”: “Question”, “name”: “What is the latency from India to Google Cloud?”, “acceptedAnswer”: {“@type”: “Answer”, “text”: “With the Mumbai region (asia-south1), typical latency is 5-15ms from major Indian cities. This is suitable for real-time monitoring applications.”}}]}
Ready to Build Your IoT Project?
Browse our complete collection of ESP32 boards, sensors, and IoT components. Fast shipping across India with technical support.
Add comment