Today, I’m improving my previous article on RFM12 communication implementing a bidirectional communication between two BugOne boards.
To ensure a bidirectional communication is really happening, I’ll be using the code from BugOne’s github project: app_noapp_skel. This project basically takes any messages received by the RFM12 and sends it back reverted.
I modified the sniffer’s source code (see below) to not only receive but also send messages to be inverted by the first board.
#!/usr/bin/python2 #-*- coding: utf-8 -*- import rfm12 import sys, time device = "/dev/ttyUSB0" baudrate = 38400 if len(sys.argv) >= 2: device = sys.argv if len(sys.argv) >= 3: baudrate = int(sys.argv) sniffer = rfm12.SnifferSerial(device) toSend = "Hello world!" count = 0 while True: sniffer.send(toSend) message = sniffer.waitForMessage() print count, if message: print "Response:", str(message) else: print "No response :(" count += 1 time.sleep(1)
Once launched, this code will send “Hello world!” to the other RFM12 module. One should not that “the other board” would be all the other boards if more were present since RFM12 is broadcasting messages. The library from dasLabor implements an anti-collision mechanism.
The result in my terminal is visible below, I receive inverted “Hello world!”.
Also, more LEDs of my boards are blinking. First the LED1 (red) from sniffer toggles on message sent. Then, on message reception, the LED1 (red) from second board toggles and finally when message is sent back and received by the sniffer it’s LED2 (blue).