[Twisted-Python] Question : Combining wokel XMPP and twisted.internet.serial
bino oetomo
bino at indoakses-online.com
Thu Dec 22 01:26:39 EST 2011
Dear Lucas Taylor
Thankyou for your fast enlightment.
It's time for me to re-build my ejabberd turnkey linux
Sincerely
-bino-
On 12/22/2011 01:12 PM, Lucas Taylor wrote:
>
>
> This is a relevant FAQ for this situation:
> http://twistedmatrix.com/trac/wiki/FrequentlyAskedQuestions#HowdoImakeinputononeconnectionresultinoutputonanother
>
>
> More specifically:
> 1. Create a Protocol class for your SerialPort that will communicate
> with the Arduino. Instances of this class will have access to the
> serial transport and can write out to the serial port. Incoming
> messages from the Arduino will be handled by the dataReceived method
> of the protocol.
>
> 2. Give your EchoBotProtocol a reference to the SerialPort somehow
> (e.g. via init), and set a reference to the EchoBotProtocol on the
> SerialPort.
>
> Here's a quick sketch:
>
> # Basic line receiver protocol
> class ArduinoReceiver(LineReceiver):
> def lineReceived(self, line):
> print "Line Received from Arduino"
> self.echobot.send('some xmpp message for which I do not know
> the format')
>
> # Wire up the serial port and protocol...note there are more
> parameters to create the SerialPort (baudrate, etc.)
> serial = SerialPort(ArduinoReceiver, '/dev/tty.usbserial', reactor)
>
> # EchoBot gets a reference to the serialport
> class EchoBotProtocol(MessageProtocol):
> def __init__(self, serial, *args, **kwargs):
> self.serial = serial
> # Set a reference to self on the serial protocol
> self.serial.protocol.echobot = self
> MessageProtocol.__init__(self, *args, **kwargs)
>
> def onMessage(self, msg):
> self.serial.transport.write('some message\n')
>
> echobot = EchoBotProtocol(serial)
>
> ...and an update to your pastebin that may be helpful for context:
> http://pastebin.com/2EJ22wXa
>
>
>
More information about the Twisted-Python
mailing list