{"id":15501900,"url":"https://github.com/gadicc/espruino-gc-meteor","last_synced_at":"2025-04-22T23:07:57.581Z","repository":{"id":15712755,"uuid":"18450781","full_name":"gadicc/espruino-gc-meteor","owner":"gadicc","description":null,"archived":false,"fork":false,"pushed_at":"2014-04-07T05:02:32.000Z","size":224,"stargazers_count":10,"open_issues_count":0,"forks_count":4,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-02-24T10:11:19.886Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gadicc.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":"2014-04-04T19:48:53.000Z","updated_at":"2019-11-19T14:56:00.000Z","dependencies_parsed_at":"2022-09-01T05:13:00.109Z","dependency_job_id":null,"html_url":"https://github.com/gadicc/espruino-gc-meteor","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/gadicc%2Fespruino-gc-meteor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gadicc%2Fespruino-gc-meteor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gadicc%2Fespruino-gc-meteor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gadicc%2Fespruino-gc-meteor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gadicc","download_url":"https://codeload.github.com/gadicc/espruino-gc-meteor/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241864379,"owners_count":20033162,"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-10-02T09:06:21.998Z","updated_at":"2025-03-04T14:30:43.324Z","avatar_url":"https://github.com/gadicc.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"## espruino-gc-meteor\n\n*[Espruino](http://www.espruino.com/) + [Meteor](https://www.meteor.com/) = \u003c3*\n\nThis is the code used in the [demo](https://www.youtube.com/watch?v=Pjbq2yqyPYM),\nand discussed on the [espruino board](http://forum.espruino.com/conversations/1020/)\nand [meteor group](https://groups.google.com/forum/#!topic/meteor-talk/SYCjJk5cpPo).\n\nPlease consider it more of a proof-of-concept than even a preview release.\nNotably, there is no API yet.  You are welcome to play around with the given\nexample, but expect changes [especially in the Meteor API].  Some things\nmight change to an object orientated approach, I'm still considering the\nmemory and CPU implications.\n\nRegrettably this was just a weekend project, to take a break from crazy pressure\nat work which I have to get back to now, but hope to resume work on it soon.  Next\nrelease would have an API and server-to-server DDP.  Definitely intend to invest\nmore in this as time allows.\n\nAll the code is in the `gc-meteor-full.js` file, it was just easier to work like\nthis in the new IDE.  Regarding the `gc-` prefix, this is to emphasize that these\naren't official packages for SockJS and Meteor, but partial implementations by me.\nI guess router could be just `router`, after I've spent more time with it.\n\nAPI's for Router and SockJS are below, but you don't really need to use them directly\nbeyond including them.  The Meteor example from the video follows below first, and the\nactual website code is in the `website` directory.  But before all that:\n\n### How to setup the Demo\n\n1. Install Meteor (see [meteor.com](http://www.meteor.com/) for more info).\n\n    ```bash\n    $ curl https://install.meteor.com/ | sh\n    ```\n\n1. Clone the repo:\n\n    ```bash\n    $ git clone https://github.com/gadicc/espruino-gc-meteor.git\n    ```\n\n1. Load `espruino-gc-meteor/gc-meteor-full.js` into the Espruino IDE, edit the lines\nat the top to include your WIFI ESSID and Passphrase:\n\n    ```js\n    var WIFI_ESSID = \"XXX\";\n    var WIFI_PASSPHRASE = 'XXX';\n    ```\n    \n    and then deploy to the board.  Note, the interesting stuff is at the bottom of\n    this file, under the --- example.js --- heading.  `router`, `sockjs`, `meteor`, etc\n    will ultimately all become their own modules, it was just easier to code like this with\n    the new IDE.\n\n1. `cd espruino-gc-meteor/website`\n\n1. Edit `espruino.js`, and change the IP address near the bottom of the file to\nthat of your Espruino (once `gc-meteor-full.js` is fully loaded, it will tell you\nthe board's IP):\n\n    ```js\n    espruino = DDP.connect('http://192.168.1.121/');\n    ```\n\n1. Run Meteor in that directory:\n\n    ```js\n    $ meteor\n    ```\n\n    and connect to [http://localhost:3000/](http://localhost:3000/) (or specify a different port with `-p port`).\n\n### Meteor Examples\n\nObviously in the future there'll be a cleaner API, possibly OO (see note above),\nand examples for how to make your own collections and methods for servos,\nsensors, etc.\n\n```js\nvar WIFI_ESSID = \"XXX\";\nvar WIFI_PASSPHRASE = 'XXX';\n\nvar router = require('gc-router').router;\nvar sockjs = require('gc-sockjs').sockjs;\n\nsockjs.router(router);\nmeteor.sockjs(sockjs);\n\nrouter.addRoute('/', function(req, res) {\n  res.writeHead(200);\n  res.end(\"Hello World\");\n});\n\nmeteor.settablePins({\n  'LED1': { color: 'red', state: false },\n  'LED2': { color: 'green', state: false },\n  'LED3': { color: 'blue', state: false }\n});\n\nmeteor.watchPins(['BTN']);\n\nconsole.log('Loading CC3000 module...');\nvar wlan = require(\"CC3000\").connect();\nconsole.log('Finished loading CC3000 module.');\n\nconsole.log('Connecting to Access Point \"' + WIFI_ESSID + '\"...');\nwlan.connect(WIFI_ESSID, WIFI_PASSPHRASE, function (s) {\n  console.log('Connected, got \"' + s + '\"');\n  if (s==\"dhcp\") {\n    console.log(\"My IP is \"+wlan.getIP().ip);\n    var http = require(\"http\");\n    var server = http.createServer(router.incoming).listen(80);  \n  }\n});\n```\n\n### Router\n\nUse like this:\n\n```js\nvar router = require('gc-router').router;\n\nrouter.addRoute('/', function(req, res) {\n  res.writeHead(200);\n  res.end(\"Hello World\");\n});\n\nconsole.log('Loading CC3000 module...');\nvar wlan = require(\"CC3000\").connect();\nconsole.log('Finished loading CC3000 module.');\n\nconsole.log('Connecting to Access Point \"' + WIFI_ESSID + '\"...');\nwlan.connect(WIFI_ESSID, WIFI_PASSPHRASE, function (s) {\n  console.log('Connected, got \"' + s + '\"');\n  if (s==\"dhcp\") {\n    console.log(\"My IP is \"+wlan.getIP().ip);\n    var http = require(\"http\");\n    var server = http.createServer(router.incoming).listen(80);  \n  }\n});\n```\n\nA asterisk (\"*\") wildcard is supported as the final character in the\npath.  Nothing fancier than that yet (there is no RegExp implementation\nin Espruino).  Potentially we could have an extra argument to match\nagainst parsed query parameters.\n\n### SockJS\n\nWill probably be completely abandoned once we get native\nwebsocket support [issue #258](https://github.com/espruino/Espruino/issues/258).\n\nAccepts connections on the `/sockjs` prefix.  Partial implementation\nof sockJS protocol, but enough to play with.  You can setup handlers\nfor received data and send data back to the client.\n\n```js\nvar sockjs = require('gc-sockjs').sockjs;\nsockjs.router(router);  // add routes to router\n\n// receive data\nsockjs.onMsg('msg', function(data) {\n\t// send reply (or sending in general)\n\tsockjs.send(this, {\n\t\tmsg: 'something'\n\t\tother: 'data',\n\t\tandMore: 'data'\n\t});\n});\n```\n\n`this` in handlers is the `session` object.  You should keep track of\n`session.sessionId` to know who to talk to (they're all in `sockjs.sessions`).\n`sockjs.getSession(id)` will return the session object if the `id` is known.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgadicc%2Fespruino-gc-meteor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgadicc%2Fespruino-gc-meteor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgadicc%2Fespruino-gc-meteor/lists"}