92 lines
3 KiB
C++
92 lines
3 KiB
C++
/*****************************************************************************
|
||
* ParticleSoftSerial library (PSS_SimpleTest.ino)
|
||
* Copyright (c) 2016 Free Software Foundation. All right reserved.
|
||
* Written by Andreas Rothenw<6E>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);
|
||
}
|