Initial commit
Dependencies: ConfigFile FXOS8700CQ M2XStreamClient-JMF MODSERIAL SDFileSystem WNCInterface jsonlite mbed-rtos mbed
Fork of StarterKit_M2X_DevLab by
config_me.h
- Committer:
- korycanjan
- Date:
- 2018-04-05
- Revision:
- 15:c63a080c6814
- Parent:
- 14:6034f6896f22
- Child:
- 16:358604977188
File content as of revision 15:c63a080c6814:
const char* hStreamName = "humidity"; // Humidity stream ID const char* tStreamName = "temp"; // Temperature stream ID const char* accelStreamNames[] = { "accelX", "accelY", "accelZ" }; // Accelerometer stream IDs class Configuration { public: char deviceId[33], // Device you want to post to m2xKey[33], // Your M2X API Key or Master API Key udpHost[30], devIMEI[16]; bool enableM2X, enableCommands, enableUDP, m2xConfigured; int commandDelay, // how many seconds we should wait between polling for a command commandPolls, // how many times we should poll for a command udpPort; double locLat, locLong; Configuration(): deviceId(""), m2xKey(""), enableM2X(true), enableCommands(false), enableUDP(false), commandDelay(10), commandPolls(6) { if (cfg.read("/sd/config.ini")) { cfg.getValue("Device_ID", deviceId, sizeof(deviceId)); cfg.getValue("M2X_Key", m2xKey, sizeof(m2xKey)); cfg.getValue("UDP_Host", udpHost, sizeof(udpHost)); cfg.getValue("IMEI", devIMEI, sizeof(devIMEI)); char buff[15]; int aux; cfg.getValue("Enable_M2X", buff, sizeof(buff)); enableM2X = strcmp(buff, "1") == 0; cfg.getValue("M2X_Commmands", buff, sizeof(buff)); enableCommands = strcmp(buff, "1") == 0; cfg.getValue("Enable_UDP", buff, sizeof(buff)); enableUDP = strcmp(buff, "1") == 0; cfg.getValue("Command_Wait", buff, sizeof(buff)); aux = atoi(buff); if ((aux > 0) && (aux < 3600)) commandDelay = aux; cfg.getValue("Command_Polls", buff, sizeof(buff)); aux = atoi(buff); if ((aux > 0) && (aux < 10)) commandPolls = aux; cfg.getValue("UDP_Port", buff, sizeof(buff)); aux = atoi(buff); if ((aux > 0) && (aux < 65535)) udpPort = aux; double lat, lon; cfg.getValue("Latitude", buff, sizeof(buff)); lat = atof(buff); cfg.getValue("Latitude", buff, sizeof(buff)); lon = atof(buff); if ((lat >= -90) && (lat <= 90) && (lon >= -180) && (lon <= 180)) { locLat = lat; locLong = lon; } } m2xConfigured = *deviceId && *m2xKey; enableCommands &= enableM2X; }; void dumpConfig(Serial& pc) { pc.printf("# config.ini" CRLF); pc.printf("Enable_M2X=%d" CRLF, enableM2X ? 1 : 0); pc.printf("Device_ID=%s" CRLF, deviceId); pc.printf("M2X_Key=%s" CRLF, m2xKey); pc.printf("M2X_Commands=%d" CRLF, enableCommands ? 1 : 0); pc.printf("#" CRLF); pc.printf("Enable_UDP=%d" CRLF, enableUDP ? 1 : 0); pc.printf("UDP_Host=%s" CRLF, udpHost); pc.printf("UDP_Port=%d" CRLF, udpPort); pc.printf("IMEI=%s" CRLF, devIMEI); pc.printf("Latitude=%f" CRLF, locLat); pc.printf("Longitude=%f" CRLF, locLong); pc.printf("#" CRLF); pc.printf("Command_Wait=%d" CRLF, commandDelay); pc.printf("Command_Polls=%d" CRLF, commandPolls); } private: ConfigFile cfg; };