Jump to content

Language support and tcp protocol documentation


Xenna

Recommended Posts

I have three questions/suggestions:

 

1. You support quite a few languages, but unfortunately my favorites aren't there. Are you planning any support for Perl and PHP? Especially on the Linux platform there are lots of programmers using these two. PHP would be great for web integration.

 

2. I understand that the API's talk TCP to a brickd daemon. It's easy to do TCP connections in (almost?) any language, so if the brickd TCP protocol is documented we could use that instead of the API. (or write our own API)

 

3. There are standards for talking to hardware via the filesystem in Linux (/sys/class or /proc). Have you considered using these?

 

That way controlling bricks and bricklets could be as easy as:

echo 1 > /sys/class/bricklets/dualrelay1

echo "Hello world" > /sys/class/bricklets/lcd1/line1

 

Or reading as easy as:

cat /sys/class/bricklets/analog1

 

It's not so easy to do events this way, but for simple polling or controlling this would do very nicely. You would immediately have added support to every language available on the Linux platform.

 

Link zu diesem Kommentar
Share on other sites

1. You support quite a few languages, but unfortunately my favorites aren't there. Are you planning any support for Perl and PHP? Especially on the Linux platform there are lots of programmers using these two. PHP would be great for web integration.

Currently we are working on OS X support and the RS485 Extension, after that we will probably make the firmware for the Encoder Bricklets (they make the driver Bricks a lot more usefull) and then i intend to add more languages.

 

2. I understand that the API's talk TCP to a brickd daemon. It's easy to do TCP connections in (almost?) any language, so if the brickd TCP protocol is documented we could use that instead of the API. (or write our own API)

Yes, it is probably a good idea to document the protocol we are speaking. It is certainly possible to speak the protocol in every language, there is no magic involved.

 

3. There are standards for talking to hardware via the filesystem in Linux (/sys/class or /proc). Have you considered using these?

 

That way controlling bricks and bricklets could be as easy as:

echo 1 > /sys/class/bricklets/dualrelay1

echo "Hello world" > /sys/class/bricklets/lcd1/line1

 

Or reading as easy as:

cat /sys/class/bricklets/analog1

 

It's not so easy to do events this way, but for simple polling or controlling this would do very nicely. You would immediately have added support to every language available on the Linux platform.

 

8)

One of our very first ideas was that a Brick could anounce itself as a mass storage device to the PC with a filesystem as described by you. But, as you said the events are problamatic and the events are very very important if you want any kind of performance over USB. For example if you have a few sensors in a stack over USB and you want to control a motor at the same time, you will be amazed how little bandwith there is left for the motor controlling if you are polling the sensors with a high frequency. Where as events with e.g a period of 10ms per sensor wouldn't be any problem.

 

However, it would be possible to write another daemon that sits behind the Brick Daemon and generates a /sys like filesystem that can be used from everywhere. It probably would have a lot in common with the generators we use to generate the language bindings. So if there is someone that would be interested in writing something like this, i would certainly help if there are questions or problems.

Link zu diesem Kommentar
Share on other sites

  • 2 weeks later...

I guess I had been looking for a reason to try Python, so that's what I did in the end. I got a control program running pretty quickly and using twisted I was even able to very easily convert it to a web service.

 

So now I can control and monitor my project with PHP and/or Javascript/Ajax.

 

Unfortunately I'm still waiting for my Analog In bricklets that seem to be stuck in the German mail... :(

 

 

Link zu diesem Kommentar
Share on other sites

  • 1 month later...

I got a control program running pretty quickly and using twisted I was even able to very easily convert it to a web service.

 

So now I can control and monitor my project with PHP and/or Javascript/Ajax.

 

Would like to share your your Python script with us? espaecally for those like me which like to play arround with webservices.

 

(but somebody of the admins said, perhaps the php bindings could be released next week.)

 

greets from germany...

Chris

Link zu diesem Kommentar
Share on other sites

I got a control program running pretty quickly and using twisted I was even able to very easily convert it to a web service.

 

So now I can control and monitor my project with PHP and/or Javascript/Ajax.

 

Would like to share your your Python script with us? espaecally for those like me which like to play arround with webservices.

 

(but somebody of the admins said, perhaps the php bindings could be released next week.)

 

greets from germany...

Chris

 

I'm not ready to share my code, probably never will, but I distilled a small sample Q&D web service out of it that's probably more useful to you.

 

This one allows a http request to retrieve the status of a temperature bricklet in XML. The request is in the form

 

http://hostname:8888/temp/status

 

Data returned is:

 

<response>
<temperature>20.50</temperature>
</response>

 

The Python code:

 

#!/usr/bin/env python

BRICKD_HOST = "localhost"
BRICKD_PORT = 4223
WEB_SERVER_PORT = 8888
TEST_MODE = False


from tinkerforge.ip_connection import IPConnection
from tinkerforge.bricklet_temperature import Temperature
from twisted.web import server, resource
from twisted.internet import reactor


if __name__ == "__main__":

    ipcon = IPConnection( BRICKD_HOST, BRICKD_PORT ) # Create ip connection to brickd

    thermo = Temperature("6KG")
    ipcon.add_device(thermo)
    print "Listening on port %d" % WEB_SERVER_PORT

    class Simple(resource.Resource):
        isLeaf = True
        def render_GET(self, request):
            uri = request.uri
            cat,cmd = uri.lstrip( '/' ).split( '/', 1 )
            if cat == 'temp':
                print "temp cmd='%s'" % cmd
                arg = cmd.split( '/' )
                if arg[0] == 'status':
                    request.setHeader( 'Content-Type', 'text/xml' )
                    s = "<temperature>%.2f</temperature>\n" % (thermo.get_temperature() / 100.0)
                    return "<response>\n" + s + "</response>\n" # Convert to XML
            return "<html>Error</html>"

    site = server.Site(Simple())
    reactor.listenTCP( WEB_SERVER_PORT, site)
    reactor.run()

 

Comments welcome, I'm a Python newbie.

 

Link zu diesem Kommentar
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Gast
Reply to this topic...

×   Du hast formatierten Text eingefügt.   Formatierung jetzt entfernen

  Only 75 emoji are allowed.

×   Dein Link wurde automatisch eingebettet.   Einbetten rückgängig machen und als Link darstellen

×   Dein vorheriger Inhalt wurde wiederhergestellt.   Clear editor

×   Du kannst Bilder nicht direkt einfügen. Lade Bilder hoch oder lade sie von einer URL.

×
×
  • Neu erstellen...