Daniel Pop
Posts: 6
Joined: Fri Jul 29, 2016 7:18 am

Communication between two RPis issue

Mon Aug 08, 2016 11:06 am

Hello there ! First of all I'm doing a Raspberry Pi 3 Model B project. It's about RFID tag reader and communication between two RPis using LAN. I've managed to do a big part of it but in the end I need to have a counter for the tags that have been read and that counter I want to send to the other RPi. My problem is that when I'm scanning the tag, it says that it must be a string or buffer, not an int, and it obviously works for a letter or a message to be sent... So, how cand I send that counter?? which is a number...

Here is the code, please help ! :(

import MFRC522
import signal
import socket


continue_reading = True
MIFAREReader = MFRC522.MFRC522()
CounterA=0
CounterB=0
UDP_IP = "10.190.54.49"
UDP_PORT = 5005
A= "Card A"
B= "Card B"


CardA = [245,193,46,80,74]
CardB = [39,150,177,101,101]

def end_read(signal, frame):
global continue_reading
continue_reading = False
print "Ctrl+C captured, ending read."
MIFAREReader.GPIO_CLEEN()

signal.signal(signal.SIGINT, end_read)

while continue_reading:
(status,TagType) = MIFAREReader.MFRC522_Request(MIFAREReader.PICC_REQIDL)
if status == MIFAREReader.MI_OK:
print "Card detected"
(status,backData) = MIFAREReader.MFRC522_Anticoll()
if status == MIFAREReader.MI_OK:
print "Card read UID: "+str(backData[0])+","+str(backData[1])+","+str(backD$
if backData == CardA:
print "is Card A"
CounterA+=1
ContorA=Counter
sock = socket.socket(socket.AF_INET,
socket.SOCK_DGRAM)

sock.sendto(A, (UDP_IP, UDP_PORT))
print "CounterA=", CounterA
if CounterA == 10:
CounterA=0
print "CounterA resetat!"
elif backData == CardB:

print "is Card B"
CounterB+=1
sock = socket.socket(socket.AF_INET,
socket.SOCK_DGRAM)
sock.sendto(B, (UDP_IP, UDP_PORT))
print "CounterB=", CounterB
if CounterB == 10:
CounterB=0
print "CounterB resetat!"

scotty101
Posts: 3958
Joined: Fri Jun 08, 2012 6:03 pm

Re: Communication between two RPis issue

Mon Aug 08, 2016 1:29 pm

Can you re-post your code between [code][/code] tags?

It is very difficult to read python without the correct indentation
Electronic and Computer Engineer
Pi Interests: Home Automation, IOT, Python and Tkinter

User avatar
Paeryn
Posts: 2987
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: Communication between two RPis issue

Mon Aug 08, 2016 4:16 pm

Daniel Pop wrote:Hello there ! First of all I'm doing a Raspberry Pi 3 Model B project. It's about RFID tag reader and communication between two RPis using LAN. I've managed to do a big part of it but in the end I need to have a counter for the tags that have been read and that counter I want to send to the other RPi. My problem is that when I'm scanning the tag, it says that it must be a string or buffer, not an int, and it obviously works for a letter or a message to be sent... So, how cand I send that counter?? which is a number...
Are you saying you've got an integer that needs to be sent, but you can only send strings? Then convert the integer to a string, send it, convert string back to integer at the other end.

Sending :

Code: Select all

counter = 23
SendMessage(str(counter)) # Whatever you do to send the string
Receiving :

Code: Select all

counter_string = ReceiveMessage() # Whatever you do to receive a string
counter = int(counter_string)
She who travels light — forgot something.

Daniel Pop
Posts: 6
Joined: Fri Jul 29, 2016 7:18 am

Re: Communication between two RPis issue

Tue Aug 09, 2016 5:29 am

scotty101 wrote:Can you re-post your code between tags?

It is very difficult to read python without the correct indentation

Sorry about that ! I've cleared it ! it needed just a str(x) for the "thing" that I want to send. Thanks a lot!

Daniel Pop
Posts: 6
Joined: Fri Jul 29, 2016 7:18 am

Re: Communication between two RPis issue

Tue Aug 09, 2016 5:30 am

Paeryn wrote:
Daniel Pop wrote:Hello there ! First of all I'm doing a Raspberry Pi 3 Model B project. It's about RFID tag reader and communication between two RPis using LAN. I've managed to do a big part of it but in the end I need to have a counter for the tags that have been read and that counter I want to send to the other RPi. My problem is that when I'm scanning the tag, it says that it must be a string or buffer, not an int, and it obviously works for a letter or a message to be sent... So, how cand I send that counter?? which is a number...
Are you saying you've got an integer that needs to be sent, but you can only send strings? Then convert the integer to a string, send it, convert string back to integer at the other end.

Sending :

Code: Select all

counter = 23
SendMessage(str(counter)) # Whatever you do to send the string
Receiving :

Code: Select all

counter_string = ReceiveMessage() # Whatever you do to receive a string
counter = int(counter_string)


Yep! That was it! Thanks man a lot ! Appreciate it !

Return to “Python”