Initial commit

Dependencies:   ConfigFile FXOS8700CQ M2XStreamClient-JMF MODSERIAL SDFileSystem WNCInterface jsonlite mbed-rtos mbed

Fork of StarterKit_M2X_DevLab by Jan Korycan

Committer:
korycanjan
Date:
Thu Apr 05 19:04:26 2018 +0000
Revision:
16:358604977188
Parent:
15:c63a080c6814
Configuration updates.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jk431j 7:721eb6bb68d3 1 const char* hStreamName = "humidity"; // Humidity stream ID
jk431j 7:721eb6bb68d3 2 const char* tStreamName = "temp"; // Temperature stream ID
jk431j 7:721eb6bb68d3 3 const char* accelStreamNames[] = { "accelX", "accelY", "accelZ" }; // Accelerometer stream IDs
jk431j 7:721eb6bb68d3 4
korycanjan 14:6034f6896f22 5 class Configuration {
korycanjan 14:6034f6896f22 6 public:
korycanjan 14:6034f6896f22 7 char deviceId[33], // Device you want to post to
korycanjan 14:6034f6896f22 8 m2xKey[33], // Your M2X API Key or Master API Key
korycanjan 14:6034f6896f22 9 udpHost[30],
korycanjan 14:6034f6896f22 10 devIMEI[16];
korycanjan 14:6034f6896f22 11
korycanjan 14:6034f6896f22 12 bool enableM2X,
korycanjan 14:6034f6896f22 13 enableCommands,
korycanjan 14:6034f6896f22 14 enableUDP,
korycanjan 14:6034f6896f22 15 m2xConfigured;
korycanjan 14:6034f6896f22 16
korycanjan 14:6034f6896f22 17 int commandDelay, // how many seconds we should wait between polling for a command
korycanjan 14:6034f6896f22 18 commandPolls, // how many times we should poll for a command
korycanjan 14:6034f6896f22 19 udpPort;
korycanjan 14:6034f6896f22 20
korycanjan 14:6034f6896f22 21 double locLat,
korycanjan 14:6034f6896f22 22 locLong;
korycanjan 14:6034f6896f22 23
korycanjan 14:6034f6896f22 24 Configuration(): deviceId(""),
korycanjan 14:6034f6896f22 25 m2xKey(""),
korycanjan 14:6034f6896f22 26 enableM2X(true),
korycanjan 14:6034f6896f22 27 enableCommands(false),
korycanjan 14:6034f6896f22 28 enableUDP(false),
korycanjan 14:6034f6896f22 29 commandDelay(10),
korycanjan 14:6034f6896f22 30 commandPolls(6)
korycanjan 14:6034f6896f22 31 {
korycanjan 14:6034f6896f22 32 if (cfg.read("/sd/config.ini")) {
korycanjan 14:6034f6896f22 33 cfg.getValue("Device_ID", deviceId, sizeof(deviceId));
korycanjan 14:6034f6896f22 34 cfg.getValue("M2X_Key", m2xKey, sizeof(m2xKey));
korycanjan 14:6034f6896f22 35 cfg.getValue("UDP_Host", udpHost, sizeof(udpHost));
korycanjan 14:6034f6896f22 36 cfg.getValue("IMEI", devIMEI, sizeof(devIMEI));
korycanjan 14:6034f6896f22 37
korycanjan 14:6034f6896f22 38 char buff[15];
korycanjan 14:6034f6896f22 39 int aux;
korycanjan 14:6034f6896f22 40
korycanjan 16:358604977188 41 if (cfg.getValue("Enable_M2X", buff, sizeof(buff)))
korycanjan 16:358604977188 42 enableM2X = strcmp(buff, "1") == 0;
korycanjan 14:6034f6896f22 43
korycanjan 16:358604977188 44 if (cfg.getValue("M2X_Commmands", buff, sizeof(buff)))
korycanjan 16:358604977188 45 enableCommands = strcmp(buff, "1") == 0;
korycanjan 16:358604977188 46
korycanjan 16:358604977188 47 if (cfg.getValue("Enable_UDP", buff, sizeof(buff)))
korycanjan 16:358604977188 48 enableUDP = strcmp(buff, "1") == 0;
korycanjan 14:6034f6896f22 49
korycanjan 16:358604977188 50 if (cfg.getValue("Command_Wait", buff, sizeof(buff))) {
korycanjan 16:358604977188 51 aux = atoi(buff);
korycanjan 16:358604977188 52 if ((aux > 0) && (aux < 3600))
korycanjan 16:358604977188 53 commandDelay = aux;
korycanjan 16:358604977188 54 };
korycanjan 14:6034f6896f22 55
korycanjan 16:358604977188 56 if (cfg.getValue("Command_Polls", buff, sizeof(buff))) {
korycanjan 16:358604977188 57 aux = atoi(buff);
korycanjan 16:358604977188 58 if ((aux > 0) && (aux < 10))
korycanjan 16:358604977188 59 commandPolls = aux;
korycanjan 16:358604977188 60 };
korycanjan 16:358604977188 61
korycanjan 16:358604977188 62 if (cfg.getValue("UDP_Port", buff, sizeof(buff))) {
korycanjan 16:358604977188 63 aux = atoi(buff);
korycanjan 16:358604977188 64 if ((aux > 0) && (aux < 65535))
korycanjan 16:358604977188 65 udpPort = aux;
korycanjan 16:358604977188 66 };
korycanjan 14:6034f6896f22 67
korycanjan 14:6034f6896f22 68 double lat, lon;
korycanjan 14:6034f6896f22 69
korycanjan 16:358604977188 70 if (cfg.getValue("Latitude", buff, sizeof(buff)))
korycanjan 16:358604977188 71 lat = atof(buff);
korycanjan 14:6034f6896f22 72
korycanjan 16:358604977188 73 if (cfg.getValue("Longitude", buff, sizeof(buff)))
korycanjan 16:358604977188 74 lon = atof(buff);
korycanjan 14:6034f6896f22 75
korycanjan 14:6034f6896f22 76 if ((lat >= -90) && (lat <= 90) && (lon >= -180) && (lon <= 180)) {
korycanjan 14:6034f6896f22 77 locLat = lat;
korycanjan 14:6034f6896f22 78 locLong = lon;
korycanjan 14:6034f6896f22 79 }
korycanjan 14:6034f6896f22 80 }
korycanjan 14:6034f6896f22 81
korycanjan 14:6034f6896f22 82 m2xConfigured = *deviceId && *m2xKey;
korycanjan 14:6034f6896f22 83
korycanjan 16:358604977188 84 enableCommands = enableM2X && enableCommands;
korycanjan 14:6034f6896f22 85 };
korycanjan 15:c63a080c6814 86
korycanjan 15:c63a080c6814 87 void dumpConfig(Serial& pc) {
korycanjan 15:c63a080c6814 88 pc.printf("# config.ini" CRLF);
korycanjan 15:c63a080c6814 89 pc.printf("Enable_M2X=%d" CRLF, enableM2X ? 1 : 0);
korycanjan 15:c63a080c6814 90 pc.printf("Device_ID=%s" CRLF, deviceId);
korycanjan 15:c63a080c6814 91 pc.printf("M2X_Key=%s" CRLF, m2xKey);
korycanjan 15:c63a080c6814 92 pc.printf("M2X_Commands=%d" CRLF, enableCommands ? 1 : 0);
korycanjan 15:c63a080c6814 93 pc.printf("#" CRLF);
korycanjan 15:c63a080c6814 94 pc.printf("Enable_UDP=%d" CRLF, enableUDP ? 1 : 0);
korycanjan 15:c63a080c6814 95 pc.printf("UDP_Host=%s" CRLF, udpHost);
korycanjan 15:c63a080c6814 96 pc.printf("UDP_Port=%d" CRLF, udpPort);
korycanjan 15:c63a080c6814 97 pc.printf("IMEI=%s" CRLF, devIMEI);
korycanjan 15:c63a080c6814 98 pc.printf("Latitude=%f" CRLF, locLat);
korycanjan 15:c63a080c6814 99 pc.printf("Longitude=%f" CRLF, locLong);
korycanjan 15:c63a080c6814 100 pc.printf("#" CRLF);
korycanjan 15:c63a080c6814 101 pc.printf("Command_Wait=%d" CRLF, commandDelay);
korycanjan 15:c63a080c6814 102 pc.printf("Command_Polls=%d" CRLF, commandPolls);
korycanjan 16:358604977188 103 pc.printf("# Data will be sent every %d seconds" CRLF, commandPolls * commandDelay);
korycanjan 15:c63a080c6814 104 }
korycanjan 14:6034f6896f22 105
korycanjan 14:6034f6896f22 106 private:
korycanjan 14:6034f6896f22 107 ConfigFile cfg;
korycanjan 14:6034f6896f22 108 };