Skip to content

Commit

Permalink
Merge pull request #6 from kaizoku-oh/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
kaizoku-oh committed May 11, 2021
2 parents 6eb17df + f7089c8 commit c453bbe
Show file tree
Hide file tree
Showing 21 changed files with 1,627 additions and 37 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Build

on:
push:
branches:
- '*'
pull_request:
branches:
- '*'

jobs:
build:
runs-on: ubuntu-latest

steps:
# Clone repo with its submodules
- uses: actions/checkout@v2
with:
submodules: true

# Install python
- name: Set up Python
uses: actions/setup-python@v2

# Install PlatformIO
- name: Set up platformio
run: |
cd examples/firestore-crud
python -m pip install --upgrade pip
pip install platformio
# Build the firmware
- name: Build Firmware
run: |
cd examples/firestore-crud
pio run
# Check the firmware
- name: Check Firmware
run: |
cd examples/firestore-crud
pio check
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "examples/firestore-crud/components/firestore"]
path = examples/firestore-crud/components/firestore
url = https://github.com/kaizoku-oh/firestore.git
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2020 Bayrem Gharsellaoui
Copyright (c) 2021 Bayrem Gharsellaoui

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
53 changes: 48 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

This project is an esp-idf component for Cloud Firestore NoSQL database as a service.

<!-- ![Firestore logo](https://github.com/kaizoku-oh/firestore/blob/main/docs/image/logo.png) -->
<!-- ![](https://github.com/<OWNER>/<REPOSITORY>/workflows/<WORKFLOW_NAME>/badge.svg) -->
[![GitHub Build workflow status](https://github.com/kaizoku-oh/firestore/workflows/Build/badge.svg)](https://github.com/kaizoku-oh/firestore/actions/workflows/main.yaml)
[![GitHub release](https://img.shields.io/github/v/release/kaizoku-oh/firestore)](https://github.com/kaizoku-oh/firestore/releases)
[![GitHub issues](https://img.shields.io/github/issues/kaizoku-oh/firestore)](https://github.com/kaizoku-oh/firestore/issues)
![GitHub top language](https://img.shields.io/github/languages/top/kaizoku-oh/firestore)
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://github.com/kaizoku-oh/firestore/blob/main/LICENSE)
[![Twitter follow](https://img.shields.io/twitter/follow/kaizoku_ouh?style=social)](https://twitter.com/kaizoku_ouh)

## Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.
Expand All @@ -10,16 +19,50 @@ These instructions will get you a copy of the project up and running on your loc

To use this component you need ESP-IDF installed on your machine, see espressif [getting started guide](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/get-started/) on how to do that natively or you can simply use [PlatformIO](https://docs.platformio.org/en/latest/tutorials/espressif32/espidf_debugging_unit_testing_analysis.html).

### Configuring the examples

Before using the example code you need to configure the firestore component in firestore_config.h which needs to contain your firestore component configuration like project id, api key... Feel free to change th configs, but the most important ones are the following:
### How to use this component with PlatformIO:

1. Install [PlatformIO Extension for vscode](https://platformio.org/install/ide?install=vscode)
2. Create a new project using ESP-IDF framework
3. Under the root of the project create a new directory called [components](https://docs.platformio.org/en/latest/frameworks/espidf.html#esp-idf-components)
4. Clone this repo under the **components** directory
``` bash
$ cd components
$ git clone https://github.com/kaizoku-oh/firestore.git
```
5. Under your project include directory create a new file called **firestore_config.h**
6. Add your Firebase project ID and API key in the **firestore_config.h** file like the following:
``` C
#define FIRESTORE_FIREBASE_PROJECT_ID "PUT_YOUR_FIREBASE_PROJECT_ID_HERE"
#define FIRESTORE_FIREBASE_API_KEY "PUT_YOUR_FIREBASE_API_KEY_HERE"
```
7. Add the following build flags in your **platformio.ini** file and change WIFI_SSID and WIFI_PASS values by your own WiFi SSID and password respectively:
``` INI
build_flags =
; Add include directory to compiler path
'-Iinclude'
; WiFi SSID defined in compile time
'-DWIFI_SSID="TYPE_YOUR_WIFI_SSID_HERE"'
; WiFi password defined in compile time
'-DWIFI_PASS="TYPE_YOUR_WIFI_PASSWORD_HERE"'
```

**Don't know where to get your API key?** easy:
##### Finally you project directory tree should look similar like the following:
```
my-project/
├── CMakeLists.txt
├── components
│   └── firestore
├── include
│   └── firestore_config.h
├── lib
├── platformio.ini
├── sdkconfig
├── src
│   ├── CMakeLists.txt
│   └── main.c
└── test
```
**Don't know where to get your API key?** Easy:
* Open you firebase console
* Go to Project settings
* Scroll down to Firebase SDK snippet
Expand All @@ -40,7 +83,7 @@ const firebaseConfig = {
## TODO

* Optimize the http code
* Add doxygene comments
* Add doxygen comments
* Add anonymous authentication
* Add CI/CD
* Add thread safety
Expand Down
31 changes: 28 additions & 3 deletions firestore_config.h → config.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,37 @@
#ifndef __FIRESTORE_CONFIG_H__
#define __FIRESTORE_CONFIG_H__
#ifndef __CONFIG_H__
#define __CONFIG_H__

#include "firestore_config.h"

#ifndef FIRESTORE_HOSTNAME
#define FIRESTORE_HOSTNAME "firestore.googleapis.com"
#endif /* FIRESTORE_HOSTNAME */

#ifndef FIRESTORE_HTTP_INTERNAL_TX_BUF_SIZE
#define FIRESTORE_HTTP_INTERNAL_TX_BUF_SIZE 1024
#endif /* FIRESTORE_HTTP_INTERNAL_TX_BUF_SIZE */

#ifndef FIRESTORE_HTTP_INTERNAL_RX_BUF_SIZE
#define FIRESTORE_HTTP_INTERNAL_RX_BUF_SIZE 1024
#endif /* FIRESTORE_HTTP_INTERNAL_RX_BUF_SIZE */

#ifndef FIRESTORE_HTTP_RX_BUF_SIZE
#define FIRESTORE_HTTP_RX_BUF_SIZE 1024*2
#endif /* FIRESTORE_HTTP_RX_BUF_SIZE */

#ifndef FIRESTORE_HTTP_PATH_SIZE
#define FIRESTORE_HTTP_PATH_SIZE 256
#endif /* FIRESTORE_HTTP_PATH_SIZE */

#ifndef FIRESTORE_FIREBASE_PROJECT_ID
#define FIRESTORE_FIREBASE_PROJECT_ID "PUT_YOUR_FIREBASE_PROJECT_ID_HERE"
#endif /* FIRESTORE_FIREBASE_PROJECT_ID */

#ifndef FIRESTORE_FIREBASE_API_KEY
#define FIRESTORE_FIREBASE_API_KEY "PUT_YOUR_FIREBASE_API_KEY_HERE"
#endif /* FIRESTORE_FIREBASE_API_KEY */

#ifndef FIRESTORE_FIREBASE_CA_CERT_PEM
/* openssl s_client -showcerts -verify 5 -connect edgecert.googleapis.com:443 < /dev/null */
#define FIRESTORE_FIREBASE_CA_CERT_PEM \
"-----BEGIN CERTIFICATE-----\r\n" \
Expand Down Expand Up @@ -35,5 +59,6 @@
"IRdAvKLWZu/axBVbzYmqmwkm5zLSDW5nIAJbELCQCZwMH56t2Dvqofxs6BBcCFIZ\r\n" \
"USpxu6x6td0V7SvJCCosirSmIatj/9dSSVDQibet8q/7UK4v4ZUN80atnZz1yg==\r\n" \
"-----END CERTIFICATE-----\r\n"
#endif /* FIRESTORE_FIREBASE_CA_CERT_PEM */

#endif /* __FIRESTORE_CONFIG_H__ */
#endif /* __CONFIG_H__ */
Binary file added docs/images/firestore.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions examples/firestore-crud/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.pio
.vscode/.browse.c_cpp.db*
.vscode/c_cpp_properties.json
.vscode/launch.json
.vscode/ipch
3 changes: 3 additions & 0 deletions examples/firestore-crud/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
cmake_minimum_required(VERSION 3.16.0)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(firestore-crud)
31 changes: 31 additions & 0 deletions examples/firestore-crud/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
## How to use this example:

1. Clone the firestore component repo into your computer
``` bash
$ git clone https://github.com/kaizoku-oh/firestore.git
```

2. Open the firestore-crud example directory with vscode
``` bash
$ code firestore/examples/firestore-crud
```

3. Update the WiFi SSID and password in the **build_flags** section in **platformio.ini** file with your real SSID and password
``` INI
'-DWIFI_SSID="MY_WIFI_SSID"'
'-DWIFI_PASS="MY_SUPER_SECRET_PASSWORD"'
```

4. Update the firebase project ID and API key in the **firestore_config.h** file
``` C
#define FIRESTORE_FIREBASE_PROJECT_ID "MY_FIREBASE_PROJECT_ID"
#define FIRESTORE_FIREBASE_API_KEY "MY_FIREBASE_API_KEY"
```
5. Now you should be ready to go: Build, upload and monitor
6. Open your [firebase console](https://console.firebase.google.com/) and go to the firestore section, you'll find that there is a new collection and a document created.
![Firestore screenshot](https://raw.githubusercontent.com/kaizoku-oh/firestore/example-update/docs/images/firestore.png)
*Finally try to play around with the code and experiment all the CRUD functionalities.*
1 change: 1 addition & 0 deletions examples/firestore-crud/components/firestore
Submodule firestore added at 9b548a
39 changes: 39 additions & 0 deletions examples/firestore-crud/include/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

This directory is intended for project header files.

A header file is a file containing C declarations and macro definitions
to be shared between several project source files. You request the use of a
header file in your project source file (C, C++, etc) located in `src` folder
by including it, with the C preprocessing directive `#include'.

```src/main.c

#include "header.h"

int main (void)
{
...
}
```

Including a header file produces the same results as copying the header file
into each source file that needs it. Such copying would be time-consuming
and error-prone. With a header file, the related declarations appear
in only one place. If they need to be changed, they can be changed in one
place, and programs that include the header file will automatically use the
new version when next recompiled. The header file eliminates the labor of
finding and changing all the copies as well as the risk that a failure to
find one copy will result in inconsistencies within a program.

In C, the usual convention is to give header files names that end with `.h'.
It is most portable to use only letters, digits, dashes, and underscores in
header file names, and at most one dot.

Read more about using header files in official GCC documentation:

* Include Syntax
* Include Operation
* Once-Only Headers
* Computed Includes

https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html
7 changes: 7 additions & 0 deletions examples/firestore-crud/include/firestore_config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#ifndef __FIRESTORE_CONFIG_H__
#define __FIRESTORE_CONFIG_H__

#define FIRESTORE_FIREBASE_PROJECT_ID "TYPE_YOUR_FIREBASE_PROJECT_ID_HERE"
#define FIRESTORE_FIREBASE_API_KEY "TYPE_YOUR_FIREBASE_API_KEY_HERE"

#endif /* __FIRESTORE_CONFIG_H__ */
7 changes: 7 additions & 0 deletions examples/firestore-crud/include/wifi_utils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#ifndef _WIFI_UTILS_H_
#define _WIFI_UTILS_H_

void wifi_initialise(void);
void wifi_wait_connected(void);

#endif /* _WIFI_UTILS_H_ */
46 changes: 46 additions & 0 deletions examples/firestore-crud/lib/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@

This directory is intended for project specific (private) libraries.
PlatformIO will compile them to static libraries and link into executable file.

The source code of each library should be placed in a an own separate directory
("lib/your_library_name/[here are source files]").

For example, see a structure of the following two libraries `Foo` and `Bar`:

|--lib
| |
| |--Bar
| | |--docs
| | |--examples
| | |--src
| | |- Bar.c
| | |- Bar.h
| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
| |
| |--Foo
| | |- Foo.c
| | |- Foo.h
| |
| |- README --> THIS FILE
|
|- platformio.ini
|--src
|- main.c

and a contents of `src/main.c`:
```
#include <Foo.h>
#include <Bar.h>

int main (void)
{
...
}

```

PlatformIO Library Dependency Finder will find automatically dependent
libraries scanning project source files.

More information about PlatformIO Library Dependency Finder
- https://docs.platformio.org/page/librarymanager/ldf.html
21 changes: 21 additions & 0 deletions examples/firestore-crud/platformio.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html

[env:esp32dev]
platform = espressif32
board = esp32dev
framework = espidf

monitor_speed = 115200
monitor_flags = --raw
build_flags =
'-Iinclude'
'-DWIFI_SSID="TYPE_YOUR_WIFI_SSID_HERE"'
'-DWIFI_PASS="TYPE_YOUR_WIFI_PASSWORD_HERE"'
Loading

0 comments on commit c453bbe

Please sign in to comment.