Official reference client implementation for Cumulocity SmartREST on u-blox C027.
Dependencies: C027_Support C12832 LM75B MMA7660 MbedSmartRest mbed-rtos mbed
Fork of MbedSmartRestMain by
io/Storage.cpp@139:f8ab852e83e7, 2016-08-08 (annotated)
- Committer:
- xinlei
- Date:
- Mon Aug 08 11:05:57 2016 +0000
- Revision:
- 139:f8ab852e83e7
- Parent:
- 113:3872569be2af
Etisalat and Teleena APN.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
vwochnik | 67:c360a2b2c948 | 1 | #include <stdio.h> |
vwochnik | 67:c360a2b2c948 | 2 | #include <string.h> |
xinlei | 97:ea056f6be2e8 | 3 | #include "MDM.h" |
vwochnik | 67:c360a2b2c948 | 4 | |
xinlei | 101:dbcd3bc51758 | 5 | #define CREDENTIALS_FILE "001_CREDENTIALS" |
vwochnik | 68:0dc778a16d0d | 6 | #define CONFIGURATION_FILE "002_CONFIGURATION" |
xinlei | 97:ea056f6be2e8 | 7 | extern MDMSerial *pMdm; |
vwochnik | 67:c360a2b2c948 | 8 | |
xinlei | 113:3872569be2af | 9 | bool loadCredential(char *tenant, char *username, char *password, size_t len) |
vwochnik | 67:c360a2b2c948 | 10 | { |
xinlei | 113:3872569be2af | 11 | char buffer[len*3+3]; |
xinlei | 101:dbcd3bc51758 | 12 | int res = pMdm->readFile(CREDENTIALS_FILE, buffer, sizeof(buffer)); |
xinlei | 111:ee9ae4a5e55c | 13 | if (res <= 0) { |
vwochnik | 67:c360a2b2c948 | 14 | return false; |
xinlei | 101:dbcd3bc51758 | 15 | } else { |
xinlei | 99:e369fc75c000 | 16 | buffer[res] = 0; |
xinlei | 113:3872569be2af | 17 | int l = sscanf(buffer, "%[^/]/%s\n%s\n", tenant, username, password); |
xinlei | 113:3872569be2af | 18 | return l==3; |
xinlei | 99:e369fc75c000 | 19 | } |
vwochnik | 67:c360a2b2c948 | 20 | } |
vwochnik | 67:c360a2b2c948 | 21 | |
xinlei | 111:ee9ae4a5e55c | 22 | bool resetCredential() |
xinlei | 98:9f2de96941c4 | 23 | { |
xinlei | 101:dbcd3bc51758 | 24 | return pMdm->delFile(CREDENTIALS_FILE); |
xinlei | 98:9f2de96941c4 | 25 | } |
xinlei | 98:9f2de96941c4 | 26 | |
xinlei | 113:3872569be2af | 27 | bool saveCredential(const char *tenant, const char *username, |
xinlei | 113:3872569be2af | 28 | const char *password, size_t len) |
vwochnik | 67:c360a2b2c948 | 29 | { |
xinlei | 113:3872569be2af | 30 | char buffer[len*3+3]; |
xinlei | 113:3872569be2af | 31 | int res = snprintf(buffer, sizeof(buffer), "%s/%s\n%s\n", tenant, username, password); |
xinlei | 111:ee9ae4a5e55c | 32 | pMdm->delFile(CREDENTIALS_FILE); |
xinlei | 101:dbcd3bc51758 | 33 | return pMdm->writeFile(CREDENTIALS_FILE, buffer, res)==res; |
vwochnik | 67:c360a2b2c948 | 34 | } |
vwochnik | 68:0dc778a16d0d | 35 | |
xinlei | 101:dbcd3bc51758 | 36 | int loadConfigFile(char *cfg, size_t len) |
vwochnik | 68:0dc778a16d0d | 37 | { |
xinlei | 97:ea056f6be2e8 | 38 | int res = pMdm->readFile(CONFIGURATION_FILE, cfg, len); |
xinlei | 101:dbcd3bc51758 | 39 | if (res >= 0) |
xinlei | 99:e369fc75c000 | 40 | cfg[res] = 0; |
xinlei | 101:dbcd3bc51758 | 41 | return res; |
vwochnik | 68:0dc778a16d0d | 42 | } |
vwochnik | 68:0dc778a16d0d | 43 | |
xinlei | 99:e369fc75c000 | 44 | bool saveConfigFile(char *cfg, size_t len) |
xinlei | 98:9f2de96941c4 | 45 | { |
xinlei | 111:ee9ae4a5e55c | 46 | pMdm->delFile(CONFIGURATION_FILE); |
xinlei | 99:e369fc75c000 | 47 | return pMdm->writeFile(CONFIGURATION_FILE, cfg, len)==len; |
xinlei | 98:9f2de96941c4 | 48 | } |