Skip to content

ICST-Technion/W22-IOT-NoCode

 
 

Repository files navigation

IOT No Code

Setup Google Cloud

  • Install gcloud command line tool

  • Authenticate with Google Cloud:

    gcloud auth application-default login

  • Create cloud project - choose your unique project name:

    gcloud projects create IOT-project

    (IOT-project is our project name)

  • Add permissions for IoT Core (so a cloud function would be able to publish):

    gcloud projects add-iam-policy-binding IOT-project --member=serviceAccount:cloud-iot@system.gserviceaccount.com --role=roles/pubsub.publisher

  • Set default values for gcloud:

    gcloud config set project YOUR_PROJECT_ID

  • Create PubSub topic for board's data (state/config):

    gcloud pubsub topics create iot-topic

    Go to "Registry details" and under "Cloud Pub/Sub topics" make sure "iot-topic" is your device state topic.

  • Create PubSub subscription for board's data:

    gcloud pubsub subscriptions create --topic iot-topic iot-subscription

  • Create PubSub topic for sensor's live data (telemetry):

    gcloud pubsub topics create sensor-data

    Go to "Registry details" and under "Cloud Pub/Sub topics" make sure "sensor-data" is your default telemetry topic.

  • Create PubSub subscription for sensor's live data:

    gcloud pubsub subscriptions create --topic sensor-data sensor-data-subscription

  • Create device registry:

    gcloud iot registries create iot-registry --region europe-west1 --event-notification-config=topic=iot-topic

  • Create Firebase app:

    Run gcloud app create --region=europe-west

    And then gcloud alpha firestore databases create --project=PROJECT_ID --region=europe-west

Deploy Google cloud functions

Use ./functions_deploy script to deploy the cloud functions and the database rules each time you make changes to them.

Setup Mongoose workspace

To be able to execute mos commands, you should install Mongoose OS client on your computer.

Please check the following tutorial for help: https://mongoose-os.com/docs/mongoose-os/quickstart/setup.md

Useful commands

  • mos build - builds the base javascript engine - should be done only once
  • mos flash - sends the engine to the device
  • mos gcp-iot-setup - registers the device with Google and sends the certificate to the device
  • mos put fs/init.js sends the updated .js code to the device - should be called on each change we want to send. A reboot needs to be done in order to make the device run the new code.
  • mos call Sys.Reboot - restarts the device with the updated code
  • mos wifi <SSID> <password> - setups the wifi on the device and reboots it. Write your wifi SSID and the password instead if "" and "".

Adding a new ESP32 controller

Use our QR generator (or any other) by running qr_generator/qr_generator.sh with the following arguments:

  • Serial Number: The id of the ESP as it appears in Google IoT-core

  • Public Key: The public key that mongoose created for you (also appears in Google IoT-core)

    Note that you are required to remove the preamble -----BEGIN PUBLIC KEY----- and the appendix -----END PUBLIC KEY-----.

After you scan the QR the authentication proccess starts. If it succeeds, the board is saved in the DB and the user's identifier is set as the board's owner.

Proccess might fail in the following scenarios:

  • The board already exists in the DB (either attached to the user who tried to add it or to a different user)
  • The board isn't registed to Google IoT-core. In this case you may need to register it again with the following command in the mos console: mos gcp-iot-setup --gcp-project <YOUR PROJECT ID> --gcp-region europe-west1 --gcp-registry iot-registry
  • An incorrect public key was inserted (or in a wrong format).

Board configuration

After you connected a device to board and added it in app, you need to configure its pins. The pins can be configured by the setting dialog which can be opened by a long tap on the device icon (in the board screen). From this dialog the device can also be removed.

ESP32 pins description

The ESP32 pins are diveded into categories as explained in this picture:

For more information browse to: https://randomnerdtutorials.com/esp32-pinout-reference-gpios/

Device configurations JSON

State update

The cloud will send configuration updates to the following topic:

/devices/<device id>/config

And the device should respond with a corresponding state update to the following topic:

/devices/<device id>/state

The configuration is in the following format:

config/state = {
	"devices": [... list of devices ...]
}

Where each device has the following attributes:

{
	"name": string,
	"active": 0 or 1,
	"pins": [... list of pins ...],
	"type": string
}

And each pin is in the following format:

{
	name: string,
	number: int,
	value: 0 or 1
}

If a pin is missing from the config JSON it will be turned off on the device.

Sensors telemetry data updates

Sensors report data in the following format:

{
	name: string,
	data: []
}

Where the data is comprised form the following attributes :

{
	time: date-"T"-hour-minute-seconds-"Z" (e.g: 2022-02-16T18:04:24Z),
	value: int
}

The data is saved in a different collection named "sensors", and the 10 most recent records are stored in the collection. These records are displayed in a graph in the sensor's screen.

Troubleshoot

Google sign-in succeed but the app's login proccess gets stuck and the following exception appears in the "run" terminal of android studio: [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: PlatformException(sign_in_failed, com.google.android.gms.common.api.ApiException: 10: , null, null)

Solution

You need to create a fingerprint in the firebase console. Go to "Project Setting" and click on "Add fingerprint". Create a SHA1 key by using a tool named "Keytool" which is built-in in windows and linux. In Windows: Open the CMD, if keytool is not included in your PATH, go to your JAVA folder in either program files or program files (x86). Search for Keytool and change your CMD current directory to this folder. run the following command: keytool -list -v -alias androiddebugkey -keystore %USERPROFILE%.android\debug.keystore In Linux/UNIX: run the following command: keytool -list -v -alias androiddebugkey -keystore ~/.android/debug.keystore enter the password: "android", copy the SHA1 key and paste it firebase fingerprint.

Google services.json is missing

Solution

You need to download this file from the firebase console. Go to "Project Setting" and click on the button google services.json. Save this file under the path: your project path\App\android\app

The esp gets stuck in a loop and emits his dump file to the console

Solution

You probably have a compilation error in init.js that made the esp crash. You need to replace it to a stable version, and execute the following commands:

  • mos build
  • mos flash

The library you added to init.js does not work

Solution

Lets say your tried to inculde adc library by using this command: load('api_adc.js'). Please make sure you also added the url of the library in your mos.yml file: "- location: https://github.com/mongoose-os-libs/adc"

Mongoose client is not running after launching mos.exe

Solution

A previous proccess of mos.exe is still running on your computer. You should open kill it and then try to launch the app again.

Running the app on an android or ios phone

Android phone

In order to be able to run the app on an android phone, you need to enable developer options and USB debugging as explained here: https://developer.android.com/studio/debug/dev-options
Afterwards, you can plug-in your phone to your computer and run the app on it just like you would if you had a simulator running.

IOS phone

Please follow the instructions in this tutorial:
https://stackoverflow.com/questions/54444538/how-do-i-run-test-my-flutter-app-on-a-real-device

About

an open source clone of blynk app, based on Mongoose OS and ESP32

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Dart 75.6%
  • TypeScript 9.9%
  • JavaScript 9.7%
  • Ruby 1.7%
  • Shell 1.6%
  • Python 0.8%
  • Other 0.7%