Hello All,
My first post as a python newbie.
I have created a project whereby I am sending binary strings to my Nano board over TCP/IP.
The output of the Nano board convert the 64bit binary string into a wiegand signal which is read by an access control system.
The actual concept works OK, but what I'm finding is after a period of time, the Nano board appears to lock up and stops working until I reset the board.
I imagine it is likely the way I've written the code and wandering whether I am somehow eating up the onboard memory?
For now I dont need to store the binary strings, because one read they imply need to output the string through wiegand on pins 2 & 3.
I'de be grateful if someone could please review my sample code below and advise?
#include <SPI.h>
#include <UIPEthernet.h>
// network configuration. gateway and subnet are optional.
// the media access control (ethernet hardware) address for the shield:
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
//the IP address for the shield:
byte ip[] = { 192, 168, 1, 50 };
// the router's gateway address:
byte gateway[] = { 192, 168, 1, 1 };
// the subnet:
byte subnet[] = { 255, 255, 255, 0 };
// telnet defaults to port 23
EthernetServer server = EthernetServer(1000);
const int W_D0 = 2; // Wiegand data 0 line is assigned to Arduino pin D2
const int W_D1 = 3; // " " 1 " " " D3
void setup()
{
// initializations code, it runs once:
pinMode(W_D0, OUTPUT);
pinMode(W_D1, OUTPUT);
digitalWrite(W_D0, 1); // set line to IDLE state
digitalWrite(W_D1, 1); // " "
//enable serial data print
Serial.begin(9600);
// initialize the ethernet device
Ethernet.begin(mac, ip, gateway, subnet);
// start listening for clients
server.begin();
}
bool alreadyConnected = false; // whether or not the client was connected previously
void loop() {
// wait for a new client:
EthernetClient client = server.available();
// when the client sends the first byte, say hello:
if (client) {
if (!alreadyConnected) {
// clear out the input buffer:
client.flush();
Serial.println("We have a new client");
client.println("Hello, client!");
alreadyConnected = true;
}
if (client.available() > 0)
{
// read the bytes incoming from the client:
char thisChar = client.read();
// echo the bytes back to the client:
server.write(thisChar);
// echo the bytes to the server as well:
Serial.write(thisChar);
//Serial.println("We have a new client");
//void Test();
if (thisChar == '0') {
//Serial.write("zero");
digitalWrite(2, LOW);
delayMicroseconds(80);
digitalWrite(2, HIGH);
delayMicroseconds(240);
}
else if (thisChar == '1')
{
//Serial.write("One");
digitalWrite(3, LOW);
delayMicroseconds(80);
digitalWrite(3, HIGH);
delayMicroseconds(240);
}
}
Wiegand.ino (3.71 KB)