X-Git-Url: https://gitweb.ps.run/matrix_esp_thesis/blobdiff_plain/948d30fa138bd6c3eef75a234c90fa5843057d4b..HEAD:/Readme.md diff --git a/Readme.md b/Readme.md index f75f65e..2049b21 100644 --- a/Readme.md +++ b/Readme.md @@ -27,6 +27,23 @@ To build the example for the ESP32 start an ESP-IDF shell in esp32/esp_project o - `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/`) @@ -42,17 +59,41 @@ To use the library in an ESP-IDF project: ## 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, @@ -62,7 +103,7 @@ MatrixClientSendEventEncrypted(&client, ``` ### Verification -``` +```c // Request an encrypted event to enable verification STATIC char eventBuffer[1024]; MatrixClientGetRoomEvent(client, @@ -77,4 +118,4 @@ STATIC char nextBatch[1024]; while (! client->verified) { MatrixClientSync(client, syncBuffer, SYNC_BUFFER_SIZE, nextBatch, 1024); } -``` \ No newline at end of file +```