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

Committer:
ansond
Date:
Wed Sep 24 19:09:30 2014 +0000
Revision:
18:a89333f9f671
Parent:
16:d196d812f651
Child:
19:1cf0bad37c62
updates

Who changed what in which revision?

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