📜 ⬆️ ⬇️

Arduino on car wash part 2

We continue to consider the use of Arduino for self-service car wash. Consider the work on the network and communication with the cash acceptor Cashcode. Start see here .

Internet client


We immediately activate the client and server:

#include <Ethernet.h> EthernetServer server(80); byte mac[] = { 0xDE, 0x23, 0xBE, 0xEF, 0xFE, 0xED }; IPAddress ip(192, 168, 1, 100); Ethernet.begin(mac, ip); server.begin(); 

We send information to the server, for example, about the accepted bill:

 int sendInfo(string pay) { EthernetClient client; if (client.connect(domenip, 80) ) { client.println("GET /get_money.php?pay="+pay+" HTTP/1.1"); client.println("Host: www.domen.ru"); client.println("Connection: keep-alive"); client.println(); } else { Serial.println("connection failed"); return 0; } delay(100); char c; while (client.available()) { c=client.read(); } client.stop(); return (1); } 

Server


Activated in the previous section. Check for requests.
')
 for (int sock = 0; sock < MAX_SOCK_NUM; sock++) { EthernetClient sclient = server.available_(sock); myserver(sclient); } 

Execute the request. In response, we derive the current value of the cost of a minute of equipment (timers).

 void myserver(EthernetClient client) { if (!client) return; char clientline[100]; int index = 0; while (client.available()) { char c = client.read(); if(index<99) clientline[index] = c; index++; } if(strstr(clientline, "water")!=NULL) digitalWrite(2, LOW); // if(strstr(clientline, "pena")!=NULL) digitalWrite(3, LOW); // if(strstr(clientline, "vosk")!=NULL) digitalWrite(4, LOW); // client.println("HTTP/1.1 200 OK"); client.println("Content-Type: text/html"); client.println("Connection: close"); client.println(); client.println("<!DOCTYPE HTML>"); client.println("<html>"); for (int j = 1; j < 6; j++) { client.print("timer "); client.print(j); client.print(" is "); client.print(EEPROM.read(j)); client.println("<br />"); } client.println("</html>"); delay(100); client.stop(); } 

Cashcode bill acceptor


Works via serial port at TTL levels using SoftwareSerial library.

 SoftwareSerial mySerial(14, 15); // RX, TX uint8_t poll[] = {0x02, 0x03, 0x06, 0x33, 0xDA, 0x81}; uint8_t ack[] = {0x02, 0x03, 0x06, 0x00, 0x0C2, 0x82}; 

As I have already said, Cashcode works under the CCNET protocol. The options are possible, it is necessary to check with the seller. The essence of the protocol is that the system periodically (several times per second is sufficient) asks the bill acceptor for its status (POOL command). He answers. If there is information in the answer, you need to confirm its receipt with the appropriate command (ACK).

Command Format: SYNC ADR LNG CMD DATA CRC

SYNC: 1 byte code [02H]
ADR: 1 byte address of bill acceptor
LNG: 1 byte * data length
CMD: 1 byte team
DATA 0 to 250 bytes
CRC: 2 bytes checksum

We send the team.

 void sendCCNET(uint8_t *com) { for(char i=0; i<com[2]; i++) mySerial.write(com[i]); } 

If the bill acceptor sent us in response the command 0x81, it means he accepted the bill. The data contains the nominal. I have this: 2 = 10 rubles, 3 = 50 rubles, 4 = 100 rubles, 5 = 500 rubles, 6 = 1000 rubles, 7 = 5000 rubles. Possible options, depending on the firmware.

Source: https://habr.com/ru/post/321172/


All Articles