X-Git-Url: https://gitweb.ps.run/matrix_esp_thesis/blobdiff_plain/344ddb2b73ca1f528ad057bcb0ee54862e0018f0..HEAD:/Readme.md diff --git a/Readme.md b/Readme.md index c4e575b..2049b21 100644 --- a/Readme.md +++ b/Readme.md @@ -9,6 +9,7 @@ Device verification is also supported. Building requires a C/C++ compiler and make. To build the dependencies run `make deps`. +All dependencies are included in this repository. To build any of the examples run `make out/examples/`. @@ -21,6 +22,34 @@ To use the library: - Add include path `ext/mjson/src/` - Add include path `ext/mongoose/` +To build the example for the ESP32 start an ESP-IDF shell in esp32/esp_project or esp32/esp_project_riscv and run: +- `idf.py build` +- `idf.py flash` +- `idf.py monitor` + +Examples for the ESP32 are in `esp32/esp_project/main`. +There are currently two, SendEncrypted and Verify. +The example can be set in `esp32/esp_project(_risc_v)/main/CMakeLists.txt` as the second argument after SRCS. + +Any code using the library should compile under ESP-IDF if the following code is added at the end of the file: +```c +#include "wifi.h" + +void +app_main(void) +{ + wifi_init(WIFI_SSID, WIFI_PASSWORD); + + main(); +} +``` + +To use the library in an ESP-IDF project: +- Add the matrix and olm components (can be found in `esp32/esp_project/components/`) +- Add `wifi.c/.h` (can be found in `esp32/esp_project/main/`) +- Add `SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fpermissive")` to CMakeLists.txt +- Call `wifi_init("", "")` before initializing the library + ## Dependencies [Mongoose](https://github.com/cesanta/mongoose) @@ -30,17 +59,41 @@ To use the library: ## Examples -### Sending an encrypted message +### (De)Initialization +```c +MatrixClient * client = (MatrixClient*)malloc(sizeof(MatrixClient)); +MatrixClientInit(client); + +MatrixHttpInit(&client->hc, SERVER); +MatrixClientSetUserId(client, USER_ID); + +MatrixClientLoginPassword(client, + USERNAME, + PASSWORD, + DEVICE_NAME); + +MatrixClientDeleteDevice(client); + +MatrixHttpDeinit(&client->hc); +``` + +### Uploading keys +```c +MatrixClientGenerateOnetimeKeys(client, 10); +MatrixClientUploadOnetimeKeys(client); +MatrixClientUploadDeviceKeys(client); ``` + +### Sending an encrypted message +```c MatrixMegolmOutSession * megolmOutSession; MatrixClientNewMegolmOutSession(&client, ROOM_ID, &megolmOutSession); -printf("megolm session id: %.10s... key: %.10s...\n", megolmOutSession->id, megolmOutSession->key); MatrixClientShareMegolmOutSession(&client, USER_ID, - "ULZZOKJBYN", + DEVICE_ID2, megolmOutSession); MatrixClientSendEventEncrypted(&client, @@ -50,7 +103,7 @@ MatrixClientSendEventEncrypted(&client, ``` ### Verification -``` +```c // Request an encrypted event to enable verification STATIC char eventBuffer[1024]; MatrixClientGetRoomEvent(client, @@ -65,4 +118,4 @@ STATIC char nextBatch[1024]; while (! client->verified) { MatrixClientSync(client, syncBuffer, SYNC_BUFFER_SIZE, nextBatch, 1024); } -``` \ No newline at end of file +```