{"id":18962265,"url":"https://github.com/lipp/tinker","last_synced_at":"2025-08-31T22:36:25.637Z","repository":{"id":3366821,"uuid":"4413248","full_name":"lipp/tinker","owner":"lipp","description":"Lua module for tinkerforge bricks and bricklets","archived":false,"fork":false,"pushed_at":"2012-10-29T15:17:51.000Z","size":269,"stargazers_count":5,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-07-11T06:43:06.832Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Lua","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lipp.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-05-22T22:06:42.000Z","updated_at":"2014-12-02T06:16:22.000Z","dependencies_parsed_at":"2022-09-01T08:50:34.499Z","dependency_job_id":null,"html_url":"https://github.com/lipp/tinker","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/lipp/tinker","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lipp%2Ftinker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lipp%2Ftinker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lipp%2Ftinker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lipp%2Ftinker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lipp","download_url":"https://codeload.github.com/lipp/tinker/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lipp%2Ftinker/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273051842,"owners_count":25037074,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-31T02:00:09.071Z","response_time":79,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-08T14:15:47.454Z","updated_at":"2025-08-31T22:36:25.595Z","avatar_url":"https://github.com/lipp.png","language":"Lua","funding_links":[],"categories":[],"sub_categories":[],"readme":"# About\n\nA Lua module for [bricks and bricklets by Tinkerforge\nGmbH](http://www.tinkerforge.com/). Allows working standalone (with\nbuilt-in event loop) or with lua-ev.\n\nThis module employs luasocket for socket communication and lua-pack\nfor serialization. It uses the TCP/IP API provided by Tinkerforge and\ndoes not bind to the C API. Thus it does not rely on pthread and does not spawn threads.\n\n# Install\n\n## Via cloning\n\n```shell \n$ git clone git://github.com/lipp/tinker.git\n$ luarocks make rockspecs/tinker-scm-1.rockspec \n```\n\n## Directly using luarocks\n\nWith LuaRocks \u003e 2.0.4.1:\n\n```shell\n$ sudo luarocks install https://raw.github.com/lipp/tinker/master/rockspecs/tinker-scm-1.rockspec\n```\n\nNote: luarocks require lua-sec for doing https requests.\nInstall with apt\n\n```shell\n$ sudo apt-get install liblua5.1-sec1\n```\nor LuaRocks\n```shell\n$ sudo luarocks install luasec\n````\n\n# Usage\n\nSee example directory.\n\n## Wrap-up\n\nNOTE: requires brickd running!\n\n```lua\n-- load module\nlocal tinker = require'tinker'\n-- create an ip connection to the brickd (default ip:localhost,port:4223).\nlocal ipcon = tinker.ipcon()\n-- create an lcd instance by specifying the stackid\nlocal lcd = ipcon:lcd_20x4(2)\n-- call some methods on the lcd object\nlcd:backlight_on()\nlcd:write_line(0,0,'Lua is awesome')\nlcd:backlight_off()\n```\n\n# API\n\nThe API tries to be very close to the APIs provided by\nTinkerforge. There are some differences though. \n\n## tinker (module)\n\n### tinker.ipcon(address,port)\n\nAn ipcon object instance is required to \"create\" bricks or bricklets.\n\n## ipcon (object)\n\n### ipcon:dispatch_events()\n\nReads all available data on the event socket and dispatches them\n(e.g. calling registered callbacks) in the current thread context.\nThis method is only required, if not using ipcon:loop() for event dispatching.\nSee [full example](https://github.com/lipp/tinker/blob/master/example/lcd20x4_buttons_ev.lua).\n\n### ipcon:event_socket()\n\nReturns the (luasocket) socket instance. Can be used to retrieve the\nfd and do async io, e.g. with lua-ev:\n\n```lua\nlocal sock = ipcon:event_socket()\nlocal fd = sock:getfd()\nlocal io = ev.IO.new(\n      function()\n         ipcon:dispatch_events()\n      end,fd,ev.READ)\n```\nSee [full example](https://github.com/lipp/tinker/blob/master/example/lcd20x4_buttons_ev.lua).\n\n### ipcon:loop()\n\nReads and dispatches incoming messages (e.g. triggering\ncallbacks). This is a very basic event loop, which only allows to\nhandle brick/bricklet events. If you need to process other events/IO,\nuse some more sophisticated event loop mechanism, like lua-ev or\nemploy a threading environment.\n\n### ipcon:enumerate(arg)\n\nDepending on the type of arg, enumerate does two different things:\n\n#### type(arg) == 'number' or type(arg) == 'nil'\n\nThis is the sync/blocking enumerate variant.\nEnumerates all available devices and returns them as a table with the\nstackid as key with sub tables which contain uuid, name and\nis_new. The call waits X seconds for the bricks/bricklets to answer\nthe enumeration before return, where X is 0.3 or arg (if arg is a number).\n\n```lua\nlocal ipcon = tinker.ipcon()\nfor stackid,dev in pairs(ipcon:enumerate()) do\n    print(stackid,dev.uuid,dev.name,dev.is_new)\nend\n```\n\n#### type(arg) == 'function'\n\nThis is the async/event based enumerate variant. It registers a Lua callback\nfunction to be called whenever devices (bricks/bricklets) \"post\" a \nCALLBACK_ENUMERATE response. The Lua function\ngets passed in the device description. The return value is a function,\nwhich can be called to trigger enumeration. \nThe example mimics the behavior of the 'sync' variant of ipcon:enumerate().\n\n```lua\nlocal ipcon = tinker.ipcon()\nlocal print_enum_dev = function(dev)\n      print(dev.uuid,dev.name,dev.stackid,dev.is_new)\nend\nlocal trigger_enum = ipcon:enumerate(print_enum_dev)\ntrigger_enum()\nipcon:loop()\n```\n\nNOTE: The uuid is NOT base 58 encoded as you see them in the brickv! \n\n### ipcon:lcd_20x4(stackid)\n\nCreates a lcd20x4 bricklet object for the device with the specified stackid.\n\n## lcd_20x4 (object)\n\nThis is an example how to use the brick/bricklet object, and how\nmethods and callbacks are mapped.\n\n### lcd_20x4:write_line(x,y,text)\n\nWrites 'text' on the display with the position specified.\n\n### lcd_20x4:clear_display()\n\nClears the entire display.\n\n### lcd_20x4:backlight_on()\n\nEnables the backlight.\n\n### lcd_20x4:backlight_off()\n\nDisables the backlight.\n\n### bool lcd_20x4:is_backlight_on()\n\nDetermines whether the backlight is on.\n\n### lcd_20x4:button_pressed(function(button_index) end)\n\nRegisters a callback, which will be called whenever a button is\npressed. The callback gets the button_index passed in.\n\n## Other bricks or bricklets\n\n### Constructor\n\nThe ipcon is required to construct a new brick or bricklet instance.\nIt provides a method called as the brick/bricklet and takes the\nstackid (NOT the uuid!) as argument: e.g.\n\n```lua\nlocal ipcon = tinker.ipcon()\nlocal imu = ipcon:imu(4) -- assume stackid 4\nlocal cur = ipcon:current_12(3) -- assume stackid 3\nlocal temp = ipcon:temperature_ir(5) -- assume stackid 5\n-- etc.\n```\n\nThe create methods are always ALL lowercase and may have underscores.\n\n### Methods\n\nThe methods are all called exactly like the TCP/IP documentation of\nthe respective brick/bricklet says:\n\n```lua\nlocal ipcon = tinker.ipcon()\nlocal imu = ipcon:imu(4) -- assume stackid 4\nlocal x,y,z = imu:get_acceleration() -- called exactly as in TCP/IP docu\n```\n\n### Callbacks\n\nThe callbacks can be registered by calling a method named like the\ncallback event (as stated in the TCP/IP documentation of the\nbrick/bricklet, but without CALLBACK_ prefix and all lowercase, e.g.:\nCALLBACK_VOLTAGE -\u003e voltage) and passing in the Lua function to be called. \nThe Lua function gets all callback data passed in as arguments (if available).\n\n```lua\nlocal ipcon = tinker.ipcon()\nlocal lcd = ipcon:lcd_20x4(6) -- assume stackid 6\n-- The TCP/IP doc calls this CALLBACK_BUTTON_PRESSED\nlcd:button_pressed(function(button_index) \n   print('button', button_index, 'pressed')\nend)\n-- block forever and wait for button press events\nipcon:loop()\n```\n\n# Status\n\nALL bricks and bricklet are \"implemented\", not all tested\nthough (need more bricks!). Feedback is very welcome!\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flipp%2Ftinker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flipp%2Ftinker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flipp%2Ftinker/lists"}