131 lines
2.3 KiB
Arduino
131 lines
2.3 KiB
Arduino
|
|
||
|
|
||
|
#include <SPI.h>
|
||
|
#include <Ethernet.h>
|
||
|
#include <Keypad.h>
|
||
|
#include <LiquidCrystal.h>
|
||
|
|
||
|
// difinicio de variable globals
|
||
|
|
||
|
// PROTOTIP - CLIENT
|
||
|
|
||
|
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
|
||
|
|
||
|
// Define the Keymap
|
||
|
|
||
|
const byte ROWS = 4; // Four rows
|
||
|
const byte COLS = 4; // Three columns
|
||
|
|
||
|
char keys[ROWS][COLS] = {
|
||
|
{
|
||
|
'1','2','3','A' }
|
||
|
,
|
||
|
{
|
||
|
'4','5','6','B' }
|
||
|
,
|
||
|
{
|
||
|
'7','8','9','C' }
|
||
|
,
|
||
|
{
|
||
|
'*','0','#','D' }
|
||
|
};
|
||
|
|
||
|
|
||
|
byte rowPins[ROWS] = {
|
||
|
17, 16, 15, 14}; //connect to the row pinouts of the keypad
|
||
|
byte colPins[COLS] = {
|
||
|
8, 9, 19, 18}; //connect to the column pinouts of the keypad
|
||
|
|
||
|
Keypad customKeypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS);
|
||
|
|
||
|
// codi del lector
|
||
|
char codigo_lector[5] = "1234";
|
||
|
|
||
|
// claus encriptacio predeterminades
|
||
|
byte keySslServer = 0x12;
|
||
|
byte keySslClient = 0x13;
|
||
|
|
||
|
|
||
|
char* peticions[] = {
|
||
|
"ping","init", "baja", "oper", "cobro", "saldo"};
|
||
|
|
||
|
|
||
|
//Configuracion de Red
|
||
|
|
||
|
// MAC
|
||
|
byte mac_lector[] = {
|
||
|
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; // mac del prototip
|
||
|
// SERVIDOR
|
||
|
char serverHostname[] = "kn.sofiethic.org"; // nom de domini del servidor
|
||
|
//const char* serverHostname = "kn.sofiethic.org"; // nom de domini del servidor
|
||
|
// client http pel lector
|
||
|
EthernetClient cliente_lector;
|
||
|
|
||
|
|
||
|
// funcio d'inicialitzacio
|
||
|
void setup()
|
||
|
{
|
||
|
|
||
|
Serial.begin(9600);
|
||
|
lcd.begin(16, 2);
|
||
|
|
||
|
Serial.println("SETUP: Attempting to obtain a DHCP lease...");
|
||
|
lcd.print("DHCP lease...");
|
||
|
|
||
|
while ( !Ethernet.begin(mac_lector) )
|
||
|
Serial.println("Failed to configure Ethernet using DHCP");
|
||
|
|
||
|
// print your local IP address:
|
||
|
Serial.print("My IP address: ");
|
||
|
for (byte thisByte = 0; thisByte < 4; thisByte++) {
|
||
|
// print the value of each byte of the IP address:
|
||
|
Serial.print(Ethernet.localIP()[thisByte], DEC);
|
||
|
Serial.print(".");
|
||
|
}
|
||
|
Serial.println();
|
||
|
|
||
|
lcd.clear();
|
||
|
lcd.print("I ");
|
||
|
lcd.print(Ethernet.localIP());
|
||
|
lcd.setCursor(0,1);
|
||
|
lcd.print("Press key *ABCD");
|
||
|
|
||
|
int result = memoryTest();
|
||
|
Serial.print("Memory test results: ");
|
||
|
Serial.print(result,DEC);
|
||
|
Serial.println(" bytes free");
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
void loop()
|
||
|
{
|
||
|
|
||
|
char key = customKeypad.getKey();
|
||
|
|
||
|
if (key != NO_KEY) {
|
||
|
//Serial.println(key);
|
||
|
keypadEvent(key);
|
||
|
}
|
||
|
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|