{"id":15107465,"url":"https://github.com/robvanlopik/toit-pharo","last_synced_at":"2025-04-05T13:42:08.713Z","repository":{"id":143353049,"uuid":"607893165","full_name":"robvanlopik/toit-pharo","owner":"robvanlopik","description":null,"archived":false,"fork":false,"pushed_at":"2023-05-28T12:07:51.000Z","size":41,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-11T09:49:19.179Z","etag":null,"topics":["iot","mqtt","pharo","toit"],"latest_commit_sha":null,"homepage":"","language":"Smalltalk","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/robvanlopik.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-02-28T22:17:11.000Z","updated_at":"2023-04-05T22:09:20.000Z","dependencies_parsed_at":"2023-06-10T18:30:31.392Z","dependency_job_id":null,"html_url":"https://github.com/robvanlopik/toit-pharo","commit_stats":{"total_commits":24,"total_committers":2,"mean_commits":12.0,"dds":"0.45833333333333337","last_synced_commit":"e62faba84674aa887a955a525de423e42c7cf304"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robvanlopik%2Ftoit-pharo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robvanlopik%2Ftoit-pharo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robvanlopik%2Ftoit-pharo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robvanlopik%2Ftoit-pharo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/robvanlopik","download_url":"https://codeload.github.com/robvanlopik/toit-pharo/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247345713,"owners_count":20924098,"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","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":["iot","mqtt","pharo","toit"],"created_at":"2024-09-25T21:24:48.047Z","updated_at":"2025-04-05T13:42:08.686Z","avatar_url":"https://github.com/robvanlopik.png","language":"Smalltalk","funding_links":[],"categories":[],"sub_categories":[],"readme":"# toit-pharo (WIP)\nThis repo contains a driver for communication between Pharo and a Toit daemon program running on an ESP32 microprocessor.\n\nCommunication is through MQTT, used in a synchronous way; the driver sends commands and waits for a response message. The driver supports digital i/o, analog i/o, PWM and I2C. (Servo in the making)\n\nFirst the program daemon.toit needs to be running on the ESP32. Then you can write in a Playground:\n```Smalltalk\nesp := ESP32Driver new brokerIP: 'mqtt://test.mosquitto.org'; deviceName: 'test1'; setup.\nesp beDigitalOutputOnPin: 2.  \"the on board LED\"\nesp digitalValue: 1 intoPin: 2. \"turn the LED on\"\n```\nIn PharoOfThingsSimplified (https://github.com/robvanlopik/Pots) there is also a driver that uses this one, so you can use the ESP32 as a PotsController.\n## Message structure\nTopics are structured as follows:\n```pots/deviceName/Command```\nwhere deviceName is used to distinguish between different devices and command is one of: (Version, Mode, DI, DO, AI, AO, PWM, I2COprn, I2CClose, I2CWrite, I2CRead, I2CReadAt, PinList, OutputList, DACList, ADCList, I2CList).\nThe message (payload) is a JSON-encoded array of parameters. Byte arrays (used in I2C operations) are base64 encoded.\nResponses from the daemon have topic ```pots/deviceName/+/Result```, where the + stands for the command name. The message contains the answer in an array (JSON encoded) that usually has as first element e.g. a pin number or i2c address.\n\n## Some limitations/todo's:\n- you will have to modify daemon.toit if your ESP32 is not on a 30  pins board, to adapt the address of the MQTT broker, to change the name of the ESP-device. I intend to use toit's asset mechanism for this.\n- you need the Toit environment to load daemon.toit. There should be a file that can be directly installed on the ESP32. Doable, but not a priority.\n- daemon.toit is not written in an OO fashion, but it is extremely simple. It also doesn't use the container model of Toit. \n- although we use asynchronous technology, the system is completely synchronous. When we want to allow out-of-band events (like state changes of gpio pins), we will have to change the design, probably along the lines of the picod system.\n- there is NO security, but it would be simple to add username/password authenitcation or TLS data transport.\n- there is NO error handling in the daemon, it will simply exit when it gets wrong input (e.g. non existing pin numbers, i/o operations to a pin that is not in that mode, etc). It may be useful to connect the device with USB to your computer and run ```jag monitor``` in a separate command shell, so you can read Toit's error messages. Used in conjunction with Pots, errors should not occur.\n- you need access to an MQTT broker. You may be able to use test.mosquitto.org, but whem you happen to have a Raspberry Pi (any) around, it is easy to install your own (see e.g. https://randomnerdtutorials.com/how-to-install-mosquitto-broker-on-raspberry-pi/)\n\n## Installing daemon.toit\nYou will need to flash the ESP32 with the toit tools, at least Jaguar. You don't need Visual Studio Code.\nIn short:\n- download and install Jaguar (https://github.com/toitlang/jaguar)\n- install toit's mqtt package: ```jag pkg install github.com/toitware/mqtt```\n- flash the device with the jaguar firmware: ```jag flash```\n- edit the file daemon.toit, at least modify the line ```host := \"test.moosquitto.org\"``` to reflect your MQTT broker\n- flash daemon.toit to the device: ```jag run daemon.toit``` or ```jag container install daemon daemon.toit```\n## Installling the driver\n``` smalltalk\nMetacello new\n  baseline: 'ESP32Driver';\n    repository: 'github://robvanlopik/toit-pharo:main';\n    load.\n```\nThis will also load the MQTT package by Sven Van Caekenberghe.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobvanlopik%2Ftoit-pharo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frobvanlopik%2Ftoit-pharo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobvanlopik%2Ftoit-pharo/lists"}