Dreamforce 2014 Demo of RFID-based Salesforce Case generation for status reporting.
Dependencies: ID12RFID ReportDB SalesforceCaseGenerator SalesforceInterface
Dependents: mbed_mqtt_endpoint_ublox_ethernet mbed_mqtt_endpoint_ublox_cellular mbed_nsp_endpoint_ublox_cellular mbed_nsp_endpoint_ublox_ethernet ... more
StatusReporter.cpp@20:660361de9b8c, 2014-09-26 (annotated)
- Committer:
- ansond
- Date:
- Fri Sep 26 04:38:23 2014 +0000
- Revision:
- 20:660361de9b8c
- Parent:
- 19:1cf0bad37c62
- Child:
- 21:2b85d1442d34
whole package now
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ansond | 0:ba3327ba3a04 | 1 | /* Copyright C2014 ARM, MIT License |
ansond | 0:ba3327ba3a04 | 2 | * |
ansond | 19:1cf0bad37c62 | 3 | * Author: Doug Anson (doug.anson@arm.com) |
ansond | 19:1cf0bad37c62 | 4 | * |
ansond | 0:ba3327ba3a04 | 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
ansond | 0:ba3327ba3a04 | 6 | * and associated documentation files the "Software", to deal in the Software without restriction, |
ansond | 0:ba3327ba3a04 | 7 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, |
ansond | 0:ba3327ba3a04 | 8 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
ansond | 0:ba3327ba3a04 | 9 | * furnished to do so, subject to the following conditions: |
ansond | 0:ba3327ba3a04 | 10 | * |
ansond | 0:ba3327ba3a04 | 11 | * The above copyright notice and this permission notice shall be included in all copies or |
ansond | 0:ba3327ba3a04 | 12 | * substantial portions of the Software. |
ansond | 0:ba3327ba3a04 | 13 | * |
ansond | 0:ba3327ba3a04 | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
ansond | 0:ba3327ba3a04 | 15 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
ansond | 0:ba3327ba3a04 | 16 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
ansond | 0:ba3327ba3a04 | 17 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
ansond | 0:ba3327ba3a04 | 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
ansond | 0:ba3327ba3a04 | 19 | */ |
ansond | 0:ba3327ba3a04 | 20 | |
ansond | 0:ba3327ba3a04 | 21 | #include "StatusReporter.h" |
ansond | 0:ba3327ba3a04 | 22 | |
ansond | 19:1cf0bad37c62 | 23 | // Logging |
ansond | 19:1cf0bad37c62 | 24 | #define LOG_CONSOLE(...) { if (this->logger() != NULL) { this->logger()->logConsole(__VA_ARGS__); } } |
ansond | 19:1cf0bad37c62 | 25 | |
ansond | 16:d196d812f651 | 26 | // temperature sensor |
ansond | 18:a89333f9f671 | 27 | AnalogIn tmp36_temp_sensor(TEMP_PIN); |
ansond | 16:d196d812f651 | 28 | |
ansond | 19:1cf0bad37c62 | 29 | StatusReporter::StatusReporter(HTTPClient *http,Logger *logger) : m_case_generator(http,logger), m_db(), m_rfid_reader(RFID_TX_PIN,RFID_RX_PIN) { |
ansond | 0:ba3327ba3a04 | 30 | this->m_logger = logger; |
ansond | 0:ba3327ba3a04 | 31 | } |
ansond | 0:ba3327ba3a04 | 32 | |
ansond | 0:ba3327ba3a04 | 33 | StatusReporter::~StatusReporter() { |
ansond | 0:ba3327ba3a04 | 34 | } |
ansond | 0:ba3327ba3a04 | 35 | |
ansond | 19:1cf0bad37c62 | 36 | Logger *StatusReporter::logger() { return this->m_logger; } |
ansond | 19:1cf0bad37c62 | 37 | |
ansond | 16:d196d812f651 | 38 | // Calculate the ambient temperature of the TMP36 sensor in C... |
ansond | 16:d196d812f651 | 39 | int StatusReporter::getLocalTemperature() { |
ansond | 16:d196d812f651 | 40 | //conversion to degrees C - from sensor output voltage per TMP36 data sheet |
ansond | 18:a89333f9f671 | 41 | float tempC = (float)(((float)tmp36_temp_sensor*3.3)-0.600)*100.0; |
ansond | 16:d196d812f651 | 42 | |
ansond | 16:d196d812f651 | 43 | // DEBUG |
ansond | 19:1cf0bad37c62 | 44 | LOG_CONSOLE("Ambient Temp: %.1f C",tempC); |
ansond | 16:d196d812f651 | 45 | |
ansond | 16:d196d812f651 | 46 | // convert to int for brevity... |
ansond | 16:d196d812f651 | 47 | return (int)tempC; |
ansond | 16:d196d812f651 | 48 | } |
ansond | 16:d196d812f651 | 49 | |
ansond | 0:ba3327ba3a04 | 50 | void StatusReporter::checkAndReportOnStatus() { |
ansond | 0:ba3327ba3a04 | 51 | // look for a readable RFID tag |
ansond | 0:ba3327ba3a04 | 52 | if(this->m_rfid_reader.readable()) { |
ansond | 0:ba3327ba3a04 | 53 | // capture the RFID id... |
ansond | 19:1cf0bad37c62 | 54 | LOG_CONSOLE("RFID: Found RFID.\r\nReading..."); |
ansond | 0:ba3327ba3a04 | 55 | int rfid = this->m_rfid_reader.read(); |
ansond | 19:1cf0bad37c62 | 56 | LOG_CONSOLE("RFID: ID %d found...\r\nProcessing...",rfid); |
ansond | 0:ba3327ba3a04 | 57 | |
ansond | 16:d196d812f651 | 58 | // look it up in our ReportDB... proceed only if we find something we know about... |
ansond | 16:d196d812f651 | 59 | char *name = this->m_db.lookupReportName(rfid); |
ansond | 0:ba3327ba3a04 | 60 | if (name != NULL) { |
ansond | 0:ba3327ba3a04 | 61 | // build out a simple subject for the case |
ansond | 4:cfa87685c859 | 62 | char subject[DB_MAX_NAME_LENGTH+1]; |
ansond | 4:cfa87685c859 | 63 | memset(subject,0,DB_MAX_NAME_LENGTH+1); |
ansond | 0:ba3327ba3a04 | 64 | sprintf(subject,"%s case update",name); |
ansond | 0:ba3327ba3a04 | 65 | |
ansond | 0:ba3327ba3a04 | 66 | // create and dispatch a case |
ansond | 14:f4ab5c7abc50 | 67 | this->m_logger->turnLEDPurple(); |
ansond | 16:d196d812f651 | 68 | char *description = this->m_db.lookupReportDescription(rfid); |
ansond | 16:d196d812f651 | 69 | char *condition = this->m_db.lookupReportCondition(rfid); |
ansond | 16:d196d812f651 | 70 | int temperature = this->getLocalTemperature(); |
ansond | 16:d196d812f651 | 71 | char *latitude = this->m_db.lookupReportLatitude(rfid); |
ansond | 16:d196d812f651 | 72 | char *longitude = this->m_db.lookupReportLongitude(rfid); |
ansond | 19:1cf0bad37c62 | 73 | bool success = this->m_case_generator.createAnonymousCase(subject,description,condition,temperature,latitude,longitude); |
ansond | 0:ba3327ba3a04 | 74 | if (success == true) { |
ansond | 19:1cf0bad37c62 | 75 | LOG_CONSOLE("Case Generated!\r\nScanning..."); |
ansond | 14:f4ab5c7abc50 | 76 | this->m_logger->turnLEDGreen(); |
ansond | 0:ba3327ba3a04 | 77 | } |
ansond | 0:ba3327ba3a04 | 78 | else { |
ansond | 19:1cf0bad37c62 | 79 | LOG_CONSOLE("Case Generation FAILED\r\nScanning..."); |
ansond | 14:f4ab5c7abc50 | 80 | this->m_logger->turnLEDYellow(); |
ansond | 0:ba3327ba3a04 | 81 | } |
ansond | 0:ba3327ba3a04 | 82 | } |
ansond | 0:ba3327ba3a04 | 83 | else { |
ansond | 0:ba3327ba3a04 | 84 | // unrecognized RFID |
ansond | 19:1cf0bad37c62 | 85 | LOG_CONSOLE("RFID %d unknown.\r\nScanning...",rfid); |
ansond | 0:ba3327ba3a04 | 86 | } |
ansond | 0:ba3327ba3a04 | 87 | } |
ansond | 0:ba3327ba3a04 | 88 | } |