{"id":18962257,"url":"https://github.com/lipp/arduino-jet","last_synced_at":"2025-04-19T11:53:11.424Z","repository":{"id":27362903,"uuid":"30838321","full_name":"lipp/Arduino-Jet","owner":"lipp","description":"Jet lib for Arduino (http://jetbus.io)","archived":false,"fork":false,"pushed_at":"2015-04-27T17:42:48.000Z","size":236,"stargazers_count":9,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-29T07:33:38.227Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C++","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":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-02-15T19:09:05.000Z","updated_at":"2021-09-06T03:20:30.000Z","dependencies_parsed_at":"2022-09-02T02:01:49.680Z","dependency_job_id":null,"html_url":"https://github.com/lipp/Arduino-Jet","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lipp%2FArduino-Jet","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lipp%2FArduino-Jet/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lipp%2FArduino-Jet/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lipp%2FArduino-Jet/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lipp","download_url":"https://codeload.github.com/lipp/Arduino-Jet/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249195435,"owners_count":21228200,"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":[],"created_at":"2024-11-08T14:15:46.711Z","updated_at":"2025-04-16T04:33:09.409Z","avatar_url":"https://github.com/lipp.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Arduino-Jet\nJet Peer lib for Arduino (http://jetbus.io).\n\nArduino-Jet enables you to easily integrate distributed web-capable Jet realtime\ncommunication with your Arduino. See [Jet Homepage](http://jetbus.io) for more\ndetails and a Live Control Center called [\"Radar\"](http://jetbus.io/radar.html).\n\nTo communicate you need either a ethernet or wifi shield or just use the Arduino's\nSerial Port.\n\nAs the Arduino's resources are rather limited, this lib does not implement every\nfeature of other [Jet](http://jetbus.io) implementations.\n\nThis library contains a modified version of [aJson](https://github.com/interactive-matter/aJson),\nwhich does not use malloc and free. DONT'T use aJson side-by-side!\n\n# Quickstart example\n\n```c++\n// add library\n#include \u003cArduinoJetPeer.h\u003e\n\n// create a global peer\nJetPeer peer;\n\n// create global states (for sensors)\nJetState* analogState;\n\n// define a function which is invoked, whenever\n// someone tries to change your state.\nbool setLedBrightness(aJsonObject* val, void* context) {\n  if (val-\u003evalueint \u003e= 0 \u0026\u0026 val-\u003evalueint \u003c= 100) {\n    // do what is required to \"really\" change the led brightness\n    return true;\n  } else {\n    return false;\n  }\n}\n\nvoid setup() {\n  ...\n  // connect to jet daemon\n  socket.connect(daemon_ip, 11122);\n\n  // pass client socket to peer\n  peer.init(socket);\n\n  // create a state with initial value and set callback function\n  peer.state(\"led/brightness\", aJson.createItem(100), setLedBrightness);\n\n  // create read-only states for sensors (providing no callback function)\n  analogState = peer.state(\"analog/1\", aJson.createItem(analogRead(0)));\n\n}\n\nvoid loop() {\n  peer.loop();\n  // post value changes\n  analogState-\u003evalue(aJson.createItem(analogRead(0)));\n  delay(100);\n}\n```\n \n# Setup\n \n1. Clone this repo to your Arduino/libraries folder (on OSX ~/Documents/Arduino/libraries).\n\n2. Install the node.js Daemon on your host machine or your \"cloud\" server:\n\n  ```sh\n  $ npm install -g node-jet\n  ```\n\n3. Start the Jet Daemon:\n\n  ```sh\n  $ jetd.js\n  ```\n\n  The default ports of the Jet Daemon are 11123 (websocket) and 11122 (raw).\n  Load the `JetExample` sketch.\n\n## with cc3000 wifi\n\n4a. Load contained example \"JetExample-cc3000\". This example uses cc3000 wifi shield.\n\n   Change the ip/server name to match the machine where the Daemon runs.\n\n  ```c++\n  #define WLAN_SSID  \"YOUR_SSID\"\n  #define WLAN_PASS  \"YOUR_PASSWORD\"\n  #define JET_DAEMON \"YOUR_IP\"\n  ```\n\n4b. Compile and upload the sketch\n\n## with Serial Port\n\n4a. Load contained example \"JetExample-Serial\".\n\n4b. Compile and upload the sketch\n\n4c. Install serialport node module\n\t\n\t```sh\n\t$ sudo npm install -g serialport\n\t```\n\n4d. Start the provided serial-to-socket script:\n\n\t```sh\n\t$ node serial-bridge.js\n\t```\n\n5. Open [Radar](http://jetbus.io/radar.html)\n\n  Enter `ws://localhost:11123` as the Daemon url.\n  Press \"connect\", press \"fetch\", watch your analog data.\n\n# API\n\n## `JetPeer` [class]\n\n### `void JetPeer::init(Client\u0026 socket)`\n\nInitializes a JetPeer instance with a Client reference. The socket must be already connected\nwith the Jet Daemon (default port 11122). The concrete class of the Client can be\nan `EthernetClient` or `Adafruit_CC3000_Client` or any other class which derives from `Client`.\n\nJetPeer::init MUST be called before any other function.\n\n```c++\nJetPeer peer;\nEthernetClient sock;\n...\nsock.connect(jet_daemon_ip, 11122); // default jet raw port\n...\npeer.init(sock);\n```\n\n### `JetState* JetPeer::state(const char* path, aJsonObject* value, [set_handler_t set_callback], [void* set_context])`\n\nAdds a state to the Daemon with the given `path` and the given `value`.\nThe set_callback is optional. When specified, the set_callback will be invoked,\nwhenever some (other) peer calls `set` with the corresponding `path`.\nThe set_context is also optional and - when specified - is passed to the set_callback\nas second param.\n\nThe max number of states is limited by JET_MAX_STATES (default=3);\n\n```c++\n// create a read only state\nJetState* test = peer.state(\"arduino/test\", aJson.createItem(123));\n```\n\n```c++\nbool setFoo(aJsonObject* val, void* context) {\n  aJsonObject* hello = aJson.getObjectItem(val, \"hello\");\n  if (hello) {\n    ...\n    return true;\n  } else {\n    return false;\n  }\n}\n...\n// create a settable state with object structure\naJsonObject* val = aJson.createObject();\naJson.addItemToObject(val, \"hello\", aJson.createItem(\"world\"));\nJetState* foo = peer.state(\"arduino/foo\", val, setFoo);\n```\n\n### `JetFetcher* JetPeer::fetch(const char* path, fetch_handler_t fetch_callback, [void* fetch_context])`\n\nSets up a new simple path based fetch. The fetch_callback is called, whenever a relevent event\n(add/remove/change) takes place. With fetch, peers can wait for other (remote) states/methods,\nsynchronize to \"master values\" or -more general - react to other stuff.\n\nThe max number of fetchers is limited by JET_MAX_FETCHERS (default=3);\n\n```c++\n\nvoid print_event(const char* path, const char* event, aJsonObject* val, void* context) {\n  Serial.println(path);\n  Serial.println(event);\n  ...\n};\n\npeer.fetch(\"master/brightness\", print_event);\n```\n\n### `JetFetcher* JetPeer::fetch(aJsonObject* fetch_expression, fetch_handler_t fetch_callback, [void* fetch_context])`\n\nSets up a new fetch. The fetch_callback is called, whenever a relevent event\n(add/remove/change) takes place. With fetch, peers can wait for other (remote) states/methods,\nsynchronize to \"master values\" or -more general - react to other stuff.\n\nThe max number of fetchers is limited by JET_MAX_FETCHERS (default=3);\n\n```c++\n\nvoid print_event(const char* path, const char* event, aJsonObject* val, void* context) {\n  Serial.println(path);\n  Serial.println(event);\n  ...\n};\n\n// create expr JSON:\n// {\n//   path:{ startsWith: \"ardu/analog\" },\n//   value: { lessThan: 100 }\n// }\n//\naJsonObject* expr = aJson.createObject();\naJsonObject* pathRule = aJson.createObject();\naJson.addItemToObject(pathRule, \"startsWith\", aJson.createItem(\"ardu/analog\"));\naJsonObject* valueRule = aJson.createObject();\naJson.addItemToObject(pathRule, \"lessThan\", aJson.createItem(100));\naJson.addItemToObject(expr, \"path\", pathRule);\naJson.addItemToObject(expr, \"value\", valueRule);\npeer.fetch(expr, print_event);\n```\n\n### `void JetPeer::set(const char* path, aJsonObject* value)`\n\nSets another state to a new value. The other state's set_callback function will\nbe invoked.\n\nNOTE: The response to the set request is not available.\n\n### `void JetPeer::call(const char* path, aJsonObject* args)`\n\nCalls a method specified by `path` with `args` (arguments). The `args` must be either\nof type JSON Object or JSON Array.\n\nNOTE: The response to the call request is not available.\n\n### `JetMethod* JetPeer::method(const char*, call_handler_t call_handler)`\n\nNOT IMPLEMENTED YET\n\n# Memory\n\nTODO doc defines / limits\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flipp%2Farduino-jet","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flipp%2Farduino-jet","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flipp%2Farduino-jet/lists"}