Created
January 17, 2018 18:23
-
-
Save pingud98/750a8bc57067d08a31adc3d36260347e to your computer and use it in GitHub Desktop.
Particle Electron reads an RFID Tag, formats it as a string and then publishes it as RFIDident
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/***************************************************************************** | |
* ParticleSoftSerial library (PSS_SimpleTest.ino) | |
* Copyright (c) 2016 Free Software Foundation. All right reserved. | |
* Written by Andreas Rothenw�nder (aka ScruffR) | |
* | |
* This sample shows sends data from Serial1 to ParticleSoftSerial(D2/D3) | |
* | |
* Prerequisites: | |
* import SparkIntervalTimer library (by Paul Kourany) | |
* wire Serial1 TX to D2 | |
* Serial1 RX to D3 (for sending ParticleSoftSerial to Serial1) | |
* | |
* Due to relatively low interrupt priorities used, baudrates greater 31250 | |
* may be prone to data corruption, depending on over all system load. | |
* | |
* This library is free software; you can redistribute it and/or | |
* modify it under the terms of the GNU Lesser General Public | |
* License as published by the Free Software Foundation; either | |
* version 2.1 of the License, or (at your option) any later version. | |
* | |
* This library is distributed in the hope that it will be useful, | |
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
* Lesser General Public License for more details. | |
* | |
* You should have received a copy of the GNU Lesser General Public | |
* License along with this library; if not, write to the Free Software | |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
*****************************************************************************/ | |
#include <ParticleSoftSerial.h> | |
#include "Particle.h" | |
#define RECEIVER SoftSer | |
#define PROTOCOL SERIAL_8N1 | |
const uint32_t baud = 9600; | |
//#if (SYSTEM_VERSION >= 0x00060000) | |
// SerialLogHandler logHandler; | |
//#endif | |
#define PSS_RX D3 // RX must be interrupt enabled (on Photon/Electron D0/A5 are not) | |
#define PSS_TX C5 //this pin isn't something we use, I couldn't find a null pin | |
ParticleSoftSerial SoftSer(PSS_RX, PSS_TX); | |
char CARDcurrent[4]; | |
void setup() | |
{ | |
Serial.begin(); | |
Serial.printlnf("ready for data"); | |
RECEIVER.begin(baud, PROTOCOL); // but SoftSerial can ;-) | |
} | |
void loop() | |
{ | |
int counter = 0; | |
unsigned long cardread = 0; | |
String cardpublish; | |
while (RECEIVER.available()) | |
{ | |
for (int cardident = 0; cardident < 5; cardident++) { | |
counter = (RECEIVER.read()); | |
if (cardident > 0) Serial.print(int(counter), HEX); | |
CARDcurrent[cardident-1] = counter; | |
Serial.print(" "); | |
} | |
Serial.println(""); | |
cardread=int(CARDcurrent[0]); | |
cardread=cardread << 8; | |
cardread=cardread+ int(CARDcurrent[1]); | |
cardread=cardread << 8; | |
cardread=cardread+ int(CARDcurrent[2]); | |
cardread=cardread << 8; | |
cardread=cardread+ int(CARDcurrent[3]); | |
Serial.println(cardread, HEX); | |
bool success; | |
success = Particle.publish("RFIDident", String(cardread, HEX), 0, PUBLIC); | |
if (!success) { | |
Serial.println("failedtopublish"); // get here if event publish did not work | |
} | |
} | |
RECEIVER.flush(); | |
if (Particle.connected()) { | |
Serial.println("Connected!"); | |
} | |
delay(1000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment