![](/media/cache/profiles/e53ba686b7ad2ec7825f0f4afff80a1b.50x50_q85.jpg)
Modificacion de https://mbed.org/cookbook/RFID-Tweeter para soporte de un tag no enlistado y registro del mismo mediante twiter
Dependencies: EthernetNetIf HTTPClient_ToBeRemoved mbed
Revision 0:8df845fb13c7, committed 2012-10-28
- Comitter:
- sherckuith
- Date:
- Sun Oct 28 04:49:16 2012 +0000
- Commit message:
- Modificacion de https://mbed.org/cookbook/RFID-Tweeter para soporte de un tag no valido y registro en twiter.
Changed in this revision
diff -r 000000000000 -r 8df845fb13c7 .hgignore --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.hgignore Sun Oct 28 04:49:16 2012 +0000 @@ -0,0 +1,6 @@ +syntax: regexp +\.hgignore +\.msub +\.meta +\.svn +\.git
diff -r 000000000000 -r 8df845fb13c7 EthernetNetIf.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/EthernetNetIf.lib Sun Oct 28 04:49:16 2012 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/donatien/code/EthernetNetIf/#bc7df6da7589
diff -r 000000000000 -r 8df845fb13c7 HTTPClient.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HTTPClient.lib Sun Oct 28 04:49:16 2012 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/donatien/code/HTTPClient_ToBeRemoved/#d0be6af2d1db
diff -r 000000000000 -r 8df845fb13c7 ID12RFID/ID12RFID.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ID12RFID/ID12RFID.cpp Sun Oct 28 04:49:16 2012 +0000 @@ -0,0 +1,53 @@ +/* mbed ID12 RFID Library + * Copyright (c) 2007-2010, sford, http://mbed.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "ID12RFID.h" + +#include "mbed.h" + +ID12RFID::ID12RFID(PinName rx) + : _rfid(NC, rx) { +} + +int ID12RFID::readable() { + return _rfid.readable(); +} + +int ID12RFID::read() { + while (_rfid.getc() != 2); + + int v = 0; + _rfid.getc(); // drop 1st 2 bytes - we actually only read the lower 32-bits of the code + _rfid.getc(); + + for (int i=7; i>=0; i--) { + char c = _rfid.getc(); // a ascii hex char + int part = c - '0'; + v |= part << (i * 4); + } + + for (int i=0; i<5; i++) { + _rfid.getc(); + } + + return v; +}
diff -r 000000000000 -r 8df845fb13c7 ID12RFID/ID12RFID.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ID12RFID/ID12RFID.h Sun Oct 28 04:49:16 2012 +0000 @@ -0,0 +1,73 @@ +/* mbed ID12 RFID Library + * Copyright (c) 2007-2010, sford, http://mbed.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef MBED_ID12RFID_H +#define MBED_ID12RFID_H + +#include "mbed.h" + +/** An interface for the ID-12 RFID reader device + * + * @code + * // Print RFID tag numbers + * + * #include "mbed.h" + * #include "ID12RFID.h" + * + * ID12RFID rfid(p10); // serial rx + * + * int main() { + * while(1) { + * if(rfid.readable()) { + * printf("RFID Tag number : %d\n", rfid.read()); + * } + * } + * } + * @endcode + */ +class ID12RFID { + +public: + /** Create an ID12 RFID interface, connected to the specified Serial rx port + * + * @param rx Recieve pin + */ + ID12RFID(PinName rx); + + /** Non blocking function to determine if an ID has been received + * + * @return Non zero value when the device is readable + */ + int readable(); + + /** A blocking function that will return a tag ID when available + * + * @return The ID tag value + */ + int read(); + +private: + Serial _rfid; + +}; + +#endif
diff -r 000000000000 -r 8df845fb13c7 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Sun Oct 28 04:49:16 2012 +0000 @@ -0,0 +1,149 @@ +// RFID Tweeter +/* + Update: 21-06-2010 + The basic authentication service for twitter is going down. + To continue using that program, the code has been updated to use http://supertweet.net which acts as an API proxy. + Simply visit the website to setup your twitter account for this API. + See: http://www.supertweet.net/about/documentation +*/ + +#include "mbed.h" +#include "ID12RFID.h" +#include "EthernetNetIf.h" +#include "HTTPClient.h" + +#include <stdio.h> +#include <stdlib.h> +#include <math.h> + +//#include <string.h> +// Function declarations +// typedef __w64 unsigned int size_t +//size_t strlen(const char *); +char *strrev(char *); +char *itoa(int, char *, int); + + + +#define TWITTER_USER "xxxx" +#define TWITTER_PASSWORD "xxxx" + +#define IDS_COUNT 4 +const int ids_list[IDS_COUNT] = {346432,340613,333651,123456}; +const char* names_list[IDS_COUNT] = {"Sophia Alava", "Angel Yaguana", "Nicolas Yaguana", "Ivan Sanchez"}; + +EthernetNetIf eth; +HTTPClient twitter; + +ID12RFID rfid(p27); +DigitalOut serching(LED1); +DigitalOut tag_present(LED2); +DigitalOut tweet_ok(LED4); + +int main() +{ + + + + printf("Init\n"); + printf("\r\nSetting up...\r\n"); + EthernetErr ethErr = eth.setup(); + if(ethErr) { + printf("Error %d in setup.\n", ethErr); + return -1; + } + printf("\r\nSetup OK\r\n"); + + while (1) { + + //printf("Serching Tag...\n"); + serching = !serching; + int id = 0; + int auth = 1; + if(rfid.readable()) { + id = rfid.read(); + tag_present = 1; + printf("Tag Serial is: %d\r\n",id); + //wait(5); + for (int i = 0; i < IDS_COUNT; i++) { + if (ids_list[i] == id) { + auth = 0; + HTTPMap msg; + msg["status"] = names_list[i]; + printf("Id: %s\r\n",names_list[i]); + msg["status"] += " Login ok!"; + printf("Mensaje HTTP: %s\n\r",msg["status"]); + twitter.basicAuth(TWITTER_USER, TWITTER_PASSWORD); + HTTPResult r = twitter.post("http://api.supertweet.net/1/statuses/update.xml", msg, NULL); + if ( r == HTTP_OK ) { + printf("Tweet sent with success!\n"); + } else { + printf("Problem during tweeting, return code %d\n", r); + } + } + } + if (auth) { + printf("Tag no found in list\r\n"); + HTTPMap msg; + msg["status"] = "Tag strange attempts to access!, Tag is: "; + int num = id; + char buf[5]; + // convert id to string [buf] + itoa(num, buf, 10); + // print our string + printf("ID tag strange: %s\n", buf); + msg["status"] += buf; + printf("Mensaje HTTP: %s\n\r",msg["status"]); + twitter.basicAuth(TWITTER_USER, TWITTER_PASSWORD); + HTTPResult r = twitter.post("http://api.supertweet.net/1/statuses/update.xml", msg, NULL); + if ( r == HTTP_OK ) { + printf("Tweet sent with success!\n"); + } else { + printf("Problem during tweeting, return code %d\n", r); + + } + auth = 1; + } + tag_present = 0; + id = 0; + } + } +} + +/* +size_t strlen(const char *string) { + const char *s; + s = string; + while (*s) + s++; + return s - string; +} +*/ + +char *strrev(char *str) { + char *p1, *p2; + if (!str || !*str) + return str; + for (p1 = str, p2 = str + strlen(str) - 1; p2 > p1; ++p1, --p2) { + *p1 ^= *p2; + *p2 ^= *p1; + *p1 ^= *p2; + } + return str; +} + +char *itoa(int n, char *s, int b) { + static char digits[] = "0123456789abcdefghijklmnopqrstuvwxyz"; + int i=0, sign; + + if ((sign = n) < 0) + n = -n; + do { + s[i++] = digits[n % b]; + } while ((n /= b) > 0); + if (sign < 0) + s[i++] = '-'; + s[i] = '\0'; + return strrev(s); +} +
diff -r 000000000000 -r 8df845fb13c7 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Sun Oct 28 04:49:16 2012 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/9114680c05da \ No newline at end of file