Dreamforce 2014 Workshop Exercise - RFID Case Generator

Dependencies:   BufferedSerial C12832 EndpointMain-rfid EthernetInterface Logger StatusReporter-df2014 mbed-rtos mbed

Fork of df-2014-workshop-rfid-case-generator-k64f by Doug Anson

Overview

This code demonstrates how to use the mbed platform with a ID-12LA RFID reader and a Freescale K64F to get data into the SalesForce cloud.
This project was generated as a workshop for DreamForce 2014..

Details

The 2014 DreamForce workshop centers around an example scenario where you, as a street light technician, will "check in" to a given street light to service it. The street lights in this example are intelligent - they are connected, have knowledge about who/what they are, and in this example, contain an RFID sensor to allow technicians to "check in" during a service event.

The purpose of the workshop exercise is to provide exposure to new developers that the mbed IDE and development environment/ecosystem is very simple and easy to setup and use. Additionally, the workshop highlights that mbed devices can directly interact with SalesForce. The slides for the workshop can be found here.

For more information about the mbed SalesForce Interface API and its use, please see: http://developer.mbed.org/teams/MBED_DEMOS/code/SalesforceInterface/

Pretty Pictures

For the workshop the mbed team designed breakout boards to connect the ID12LA to the Freescale K64F for ease of use. Pictures of the boards can be found below. If you are interested in the breakout board you can order one from the OSHPark project page or use the eagle or gerber files as you see fit.

The ID-12LA sockets onto the RFID Brekout Board which then is put onto the Freescale K64F.

/media/uploads/mbedAustin/rfidboard_-8-.small.jpg

/media/uploads/mbedAustin/rfidboard_-9-.small.jpg

Committer:
ansond
Date:
Wed Aug 27 18:30:05 2014 +0000
Revision:
6:427c387b10e7
Parent:
4:46459ed734f3
Child:
7:5d6e03557246
updates

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ansond 0:df2aa79c64f2 1 /* Copyright C2014 ARM, MIT License
ansond 0:df2aa79c64f2 2 *
ansond 0:df2aa79c64f2 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
ansond 0:df2aa79c64f2 4 * and associated documentation files the "Software", to deal in the Software without restriction,
ansond 0:df2aa79c64f2 5 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
ansond 0:df2aa79c64f2 6 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
ansond 0:df2aa79c64f2 7 * furnished to do so, subject to the following conditions:
ansond 0:df2aa79c64f2 8 *
ansond 0:df2aa79c64f2 9 * The above copyright notice and this permission notice shall be included in all copies or
ansond 0:df2aa79c64f2 10 * substantial portions of the Software.
ansond 0:df2aa79c64f2 11 *
ansond 0:df2aa79c64f2 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
ansond 0:df2aa79c64f2 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
ansond 0:df2aa79c64f2 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
ansond 0:df2aa79c64f2 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
ansond 0:df2aa79c64f2 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
ansond 0:df2aa79c64f2 17 */
ansond 0:df2aa79c64f2 18
ansond 0:df2aa79c64f2 19 // our definitions
ansond 0:df2aa79c64f2 20 #include "Definitions.h"
ansond 0:df2aa79c64f2 21
ansond 6:427c387b10e7 22 // RFID Reader - on P14 pin
ansond 6:427c387b10e7 23 #if ID12_ENABLE
ansond 6:427c387b10e7 24 #include "ID12RFID.h"
ansond 6:427c387b10e7 25 ID12RFID rfid_reader(p14);
ansond 6:427c387b10e7 26 #endif
ansond 0:df2aa79c64f2 27
ansond 0:df2aa79c64f2 28 // Salesforce Case Generator
ansond 0:df2aa79c64f2 29 #include "SalesForceCaseGenerator.h"
ansond 0:df2aa79c64f2 30
ansond 0:df2aa79c64f2 31 // our Logger
ansond 0:df2aa79c64f2 32 #include "Logger.h"
ansond 0:df2aa79c64f2 33
ansond 0:df2aa79c64f2 34 // our WidgetDB
ansond 0:df2aa79c64f2 35 #include "WidgetDB.h"
ansond 0:df2aa79c64f2 36
ansond 0:df2aa79c64f2 37 // our LCD Panel
ansond 0:df2aa79c64f2 38 #include "C12832_lcd.h"
ansond 0:df2aa79c64f2 39 C12832_LCD lcd;
ansond 0:df2aa79c64f2 40
ansond 0:df2aa79c64f2 41 // our Serial port
ansond 0:df2aa79c64f2 42 #include "Serial.h"
ansond 0:df2aa79c64f2 43 Serial pc(USBTX, USBRX);
ansond 0:df2aa79c64f2 44
ansond 3:03108e424931 45 // Ethernet
ansond 3:03108e424931 46 #include "EthernetInterface.h"
ansond 3:03108e424931 47 EthernetInterface ethernet;
ansond 3:03108e424931 48
ansond 6:427c387b10e7 49 // HARD RESET
ansond 6:427c387b10e7 50 extern "C" void HardFault_Handler() { NVIC_SystemReset(); }
ansond 6:427c387b10e7 51
ansond 0:df2aa79c64f2 52 // Main Entry...
ansond 0:df2aa79c64f2 53 int main() {
ansond 0:df2aa79c64f2 54 // create our object instances
ansond 0:df2aa79c64f2 55 Logger logger(&pc,&lcd);
ansond 0:df2aa79c64f2 56
ansond 0:df2aa79c64f2 57 // announce
ansond 0:df2aa79c64f2 58 logger.log("DF 2014 RFID Reader\r\nVersion: %s",APP_VERSION);
ansond 0:df2aa79c64f2 59
ansond 3:03108e424931 60 // initialize Ethernet
ansond 3:03108e424931 61 logger.log("Initializing Ethernet...");
ansond 3:03108e424931 62 ethernet.init();
ansond 0:df2aa79c64f2 63
ansond 3:03108e424931 64 // get a DHCP address and bring the network interface up
ansond 3:03108e424931 65 logger.log("Getting IP Address...");
ansond 3:03108e424931 66 if (ethernet.connect() == 0) {
ansond 3:03108e424931 67 // log our IP address (DHCP)
ansond 3:03108e424931 68 logger.log("IP Address: %s",ethernet.getIPAddress());
ansond 3:03108e424931 69
ansond 3:03108e424931 70 // create the WidgetDB
ansond 3:03108e424931 71 WidgetDB db;
ansond 3:03108e424931 72
ansond 3:03108e424931 73 // create the Salesforce Case Generator
ansond 3:03108e424931 74 SalesForceCaseGenerator case_generator(&logger);
ansond 3:03108e424931 75
ansond 3:03108e424931 76 // Enter the main loop
ansond 3:03108e424931 77 while(true) {
ansond 6:427c387b10e7 78 #if ID12_ENABLE
ansond 3:03108e424931 79 // look for a readable RFID tag
ansond 6:427c387b10e7 80 logger.log("RFID: Scanning...");
ansond 3:03108e424931 81 if(rfid_reader.readable()) {
ansond 3:03108e424931 82 // capture the RFID id...
ansond 6:427c387b10e7 83 logger.log("RFID: Found RFID.\r\nReading...");
ansond 3:03108e424931 84 int rfid = rfid_reader.read();
ansond 6:427c387b10e7 85 logger.log("RFID: ID %d found...\r\nProcessing...",rfid);
ansond 0:df2aa79c64f2 86
ansond 3:03108e424931 87 // look it up in our WidgetDB... proceed only if we find something we know about...
ansond 6:427c387b10e7 88 char *name = db.lookupWidgetName(rfid);
ansond 3:03108e424931 89 if (name != NULL) {
ansond 3:03108e424931 90 // build out a simple subject for the case
ansond 3:03108e424931 91 char subject[MAX_NAME_LENGTH+1];
ansond 3:03108e424931 92 memset(subject,0,MAX_NAME_LENGTH+1);
ansond 3:03108e424931 93 sprintf(subject,"Widget %s detected",name);
ansond 3:03108e424931 94
ansond 3:03108e424931 95 // create and dispatch a case
ansond 3:03108e424931 96 bool success = case_generator.createCase(subject,db.lookupWidgetDescription(rfid));
ansond 3:03108e424931 97 if (success == true) {
ansond 3:03108e424931 98 logger.log("Case Generated!");
ansond 3:03108e424931 99 }
ansond 3:03108e424931 100 else {
ansond 3:03108e424931 101 logger.log("Case Generation FAILED");
ansond 3:03108e424931 102 }
ansond 0:df2aa79c64f2 103 }
ansond 0:df2aa79c64f2 104 else {
ansond 3:03108e424931 105 // unrecognized RFID
ansond 3:03108e424931 106 logger.log("RFID unknown. Ignoring...");
ansond 0:df2aa79c64f2 107 }
ansond 3:03108e424931 108 }
ansond 6:427c387b10e7 109 #else
ansond 6:427c387b10e7 110 // simply create and dispatch a single case
ansond 6:427c387b10e7 111 logger.log("Creating Case...");
ansond 6:427c387b10e7 112 bool success = case_generator.createCase("sample mbed case","this is a sample mbed case");
ansond 6:427c387b10e7 113 if (success == true) {
ansond 6:427c387b10e7 114 logger.log("Case Generated!");
ansond 6:427c387b10e7 115 logger.log("Exiting...");
ansond 6:427c387b10e7 116 exit(1);
ansond 6:427c387b10e7 117 }
ansond 6:427c387b10e7 118 else {
ansond 6:427c387b10e7 119 logger.log("Case Generation FAILED");
ansond 6:427c387b10e7 120 logger.log("Exiting...");
ansond 6:427c387b10e7 121 exit(1);
ansond 6:427c387b10e7 122 }
ansond 6:427c387b10e7 123 #endif
ansond 3:03108e424931 124
ansond 3:03108e424931 125 // wait a bit and look again
ansond 3:03108e424931 126 wait_ms(WAIT_TIME_MS);
ansond 3:03108e424931 127 }
ansond 3:03108e424931 128 }
ansond 3:03108e424931 129 else {
ansond 3:03108e424931 130 logger.log("No Network... Exiting...");
ansond 6:427c387b10e7 131 exit(1);
ansond 3:03108e424931 132 }
ansond 3:03108e424931 133
ansond 3:03108e424931 134 // disconnect
ansond 4:46459ed734f3 135 logger.log("Disconnecting...");
ansond 3:03108e424931 136 ethernet.disconnect();
ansond 4:46459ed734f3 137
ansond 4:46459ed734f3 138 // Exit
ansond 6:427c387b10e7 139 logger.log("Exiting...");
ansond 6:427c387b10e7 140 exit(1);
ansond 0:df2aa79c64f2 141 }