]> gitweb.ps.run Git - matrix_esp_thesis/blob - esp32/esp_project/main/SendEncrypted.c
working examples for esp
[matrix_esp_thesis] / esp32 / esp_project / main / SendEncrypted.c
1 #define OLMLIB_VERSION_MAJOR 3
2 #define OLMLIB_VERSION_MINOR 2
3 #define OLMLIB_VERSION_PATCH 15
4
5 #define OLM_STATIC_DEFINE
6
7 #include <stdio.h>
8 #include <matrix.h>
9
10 #define SERVER       "https://matrix.org"
11 #define USER_ID      "@pscho:matrix.org"
12 #define ROOM_ID      "!XKFUjAsGrSSrpDFIxB:matrix.org"
13
14 int
15 main(void)
16 {
17     // static MatrixClient _client;
18     // MatrixClient * client = &_client;
19     MatrixClient * client = (MatrixClient*)malloc(sizeof(MatrixClient));
20     MatrixClientInit(client);
21
22     MatrixHttpInit(&client->hc, SERVER);
23     MatrixClientSetUserId(client, USER_ID);
24
25     static char key[1024];
26     MatrixOlmAccountGetDeviceKey(&client->olmAccount, key, 1024);
27     printf("key: %s\n", key);
28
29     //MatrixClientSetUserId(client, USER_ID);
30
31     MatrixClientLoginPassword(client,
32         "pscho",
33         "Wc23EbmB9G3faMq",
34         "Test1");
35
36     // MatrixClientSendEvent(client,
37     //     ROOM_ID,
38     //     "m.room.message",
39     //     "{\"body\":\"Hello\",\"msgtype\":\"m.text\"}");
40
41     MatrixClientUploadDeviceKey(client);
42     MatrixClientGenerateOnetimeKeys(client, 10);
43     MatrixClientUploadOnetimeKeys(client);
44
45     // create megolmsession
46     MatrixMegolmOutSession * megolmOutSession;
47     MatrixClientNewMegolmOutSession(client,
48         ROOM_ID,
49         &megolmOutSession);
50     printf("megolm session id: %.10s... key: %.10s...\n", megolmOutSession->id, megolmOutSession->key);
51
52     // heap_caps_get_free_size();
53     // xPortGetFreeHeapSize();
54
55     MatrixClientShareMegolmOutSession(client,
56         USER_ID,
57         "ULZZOKJBYN",
58         megolmOutSession);
59
60     MatrixClientSendEventEncrypted(client,
61         ROOM_ID,
62         "m.room.message",
63         "{\"body\":\"Hello\",\"msgtype\":\"m.text\"}");
64         
65     MatrixClientDeleteDevice(client);
66
67     MatrixHttpDeinit(&client->hc);
68
69     return 0;
70 }
71
72 #include "wifi.h"
73
74 void
75 app_main(void)
76 {
77     wifi_init("Hundehuette", "Affensicherespw55");
78
79     main();
80 }