Alvaro Viebrantz
Published © MIT

Asset Tracker using Cloud IoT Core, Firestore and MongooseOS

Track your goods anywhere and anytime with a GPS tracker sending location data over mobile network to an awesome cloud.

AdvancedFull instructions provided4 hours4,260
Asset Tracker using Cloud IoT Core, Firestore and MongooseOS

Things used in this project

Hardware components

ESP32S
Espressif ESP32S
×1
u-blox NEO-6M GPS module
×1
SIM800L GSM Module
×1
LED (generic)
LED (generic)
×2
Resistor 221 ohm
Resistor 221 ohm
×1
Resistor 1k ohm
Resistor 1k ohm
×1
Resistor 10k ohm
Resistor 10k ohm
×1
mosfet
×1

Software apps and online services

Mongoose OS
Mongoose OS
Google Cloud IoT Core
Firebase
Google Firebase
Google Maps
Google Maps

Story

Read more

Schematics

Schematic

Schematic image

Code

Code snippet #1

Plain text
# 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 YOUR_PROJECT_NAME
# Set current project
gcloud config set project YOUR_PROJECT_NAME

Code snippet #5

Plain text
# Add permissions for IoT Core
gcloud projects add-iam-policy-binding YOUR_PROJECT_NAME --member=serviceAccount:cloud-iot@system.gserviceaccount.com --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 asset-tracker-registry --region us-central1 --event-pubsub-topic=telemetry-topic

Code snippet #11

Plain text
$ mos console
Using port /dev/cu.SLAB_USBtoUART
[Jan 17 11:18:00.762] mgos_net_on_change_c PPP: connecting
[Jan 17 11:18:00.772] == Net event: 1 CONNECTING 
[Jan 17 11:18:00.811] mgos_pppos_uart_disp Starting PPP, user 'tim'
[Jan 17 11:18:00.818] mgos_net_on_change_c PPP: connected
[Jan 17 11:18:00.827] == Net event: 2 CONNECTED 
[Jan 17 11:18:00.833] mongoose_poll        New heap free LWM: 218968
[Jan 17 11:18:01.559] mgos_net_on_change_c PPP: ready, IP 179.11.108.69, GW 192.168.254.254, DNS 189.40.198.80
[Jan 17 11:18:01.572] == Net event: 3 GOT_IP 
[Jan 17 11:18:01.579] mgos_mqtt_global_con MQTT connecting to mqtt.googleapis.com:8883
[Jan 17 11:18:01.827] $GGA: fix quality: 0
[Jan 17 11:18:01.832] $GSV: sattelites in view: 3
[Jan 17 11:18:02.498] mgos_sntp_query      SNTP query to pool.ntp.org
[Jan 17 11:18:09.730] mongoose_poll        New heap free LWM: 206328
[Jan 17 11:18:09.810] mgos_mqtt_ev         MQTT TCP connect ok (0)
[Jan 17 11:18:10.834] mgos_sntp_ev         SNTP reply from 200.160.7.186: time 1516198687.979016, local 27.250466, delta 1516198660.728550
[Jan 17 11:18:24.767] mgos_mqtt_ev         MQTT CONNACK 0
[Jan 17 11:18:24.774] MQTT CONNECTED 
[Jan 17 11:18:24.782] do_subscribe         Subscribing to '/devices/esp32_3884A4/config'
[Jan 17 11:18:26.182] Got config update: {"update_interval":120}
[Jan 17 11:18:26.291] save_cfg             Saved to conf9.json
[Jan 17 11:18:26.312] Setting timer with  120  seconds interval 
[Jan 17 11:18:29.304] Published 
[Jan 17 11:18:29.307] Sleeping 
[Jan 17 11:18:37.316] Turning off all devices

Code snippet #12

Plain text
$ gcloud beta pubsub subscriptions pull --auto-ack telemetry-subscription
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                                                               DATA                                                               β”‚   MESSAGE_ID   β”‚                ATTRIBUTES               β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ {"latlon":{"sp":"0.197133","lon":"-56.082420","lat":"-15.581032"},"temp":53.333333,"free_ram":214.191406,"total_ram":287.621094} β”‚ 22138603640541 β”‚ deviceId=esp32_3884A4                   β”‚
β”‚                                                                                                                                  β”‚                β”‚ deviceNumId=2569363294223005            β”‚
β”‚                                                                                                                                  β”‚                β”‚ deviceRegistryId=asset-tracker-registry β”‚
β”‚                                                                                                                                  β”‚                β”‚ deviceRegistryLocation=us-central1      β”‚
β”‚                                                                                                                                  β”‚                β”‚ projectId=asset-tracker-iot             β”‚
β”‚                                                                                                                                  β”‚                β”‚ subFolder=                              β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Github

https://github.com/alvarowolfx/asset-tracker-gcp-mongoose-os

Credits

Alvaro Viebrantz

Alvaro Viebrantz

3 projects β€’ 25 followers
Google Developer Expert for IoT and Google Developers Group CuiabΓ‘ organizer. Public speaker on themes like Mobile, IoT and Cloud Computing.

Comments