Giter Club home page Giter Club logo

gcp-iot-app's Introduction

Google Cloud IoT Core Example App

This example consists on a fake device, which emulates a simple weather station, that is connected to Google IoT Core by MQTT protocol

Google Cloud IoT Core Setup

# Install beta components
gcloud components install beta
# Authenticate with Google Cloud
gcloud auth login
# Create cloud project - choose your unique project name
gcloud projects create MY_PROJECT_NAME
# Set current project
gcloud config set project MY_PROJECT_NAME
# Add permissions for IoT Core
gcloud projects add-iam-policy-binding MY_PROJECT_NAME --member=serviceAccount:[email protected] --role=roles/pubsub.publisher
# Create PubSub topic for device data:
gcloud beta pubsub topics create telemetry-topic
# Create PubSub subscription for device data:
gcloud beta pubsub subscriptions create --topic telemetry-topic telemetry-subscription
# Create device registry:
gcloud beta iot registries create gcp-iot-registry --region us-central1 --state-pubsub-topic=telemetry-topic

Virtual Device

Just run npm start

Big Query

Big Query is Google's low-cost, fully manageable petabyte scalable data storage service. Big Query is a stand-alone, there is no infrastructure to manage and you do not need a database administrator as it scales with your data

Steps

  • You must associate Big Query with your Google Cloud Project
  • Create a new dataset
  • Create a table (native table)
  • Create Schema

Firebase Cloud Functions

To insert data in Big Query we will use Firebase Cloud Functions, that can be configured to execute based on many different triggers and events. One of these triggers are new data inserted in a Pub/Sub topic, so we will listen to our topic associated with out Device Registry and with each data that arrives we execute a function that store the data in Big Query and mantain the last device data in Firestore Database

  • IMPORTANT: You have to enable Firestore API in Firebase console (it will be enabled in Google Cloud API too)

Steps

  • Run sudo npm i -g firebase-tools
  • Run firebase loginto authenticate Google and setup the command line tools
  • Run firebase initto associate the local project with your Firebase Project
  • Run the above code to set some environment variables
firebase functions:config:set
bigquery.datasetname="weather_station_iot"
bigquery.tablename="raw_data"

Firestore Database

Emulators

Firestore

gcloud beta emulators firestore start

Pubsub

gcloud beta emulators pubsub env-init
gcloud beta emulators pubsub start

gcp-iot-app's People

Contributors

seb7887 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.