-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathambient.m5b
1 lines (1 loc) · 3.34 KB
/
ambient.m5b
1
{"category":"ambient","color":"#2e477d","blocks":["__ambient_ambientSend"],"jscode":"// Block __ambient_ambientSend\nvar __ambient_ambientSend_json = {\n \"previousStatement\": null,\n \"nextStatement\": null,\n \"message0\": \"%1\",\n \"args0\": [\n {\n \"type\": \"field_label\",\n \"text\": \"ambient send\"\n }\n ],\n \"message1\": \"%1 %2\",\n \"args1\": [\n {\n \"type\": \"field_label\",\n \"text\": \"channelId\"\n },\n {\n \"type\": \"field_number\",\n \"value\": 0,\n \"name\": \"channelId\"\n }\n ],\n \"message2\": \"%1 %2\",\n \"args2\": [\n {\n \"type\": \"field_label\",\n \"text\": \"writeKey\"\n },\n {\n \"type\": \"field_input\",\n \"text\": \"\",\n \"spellcheck\": false,\n \"name\": \"writeKey\"\n }\n ],\n \"message3\": \"%1 %2\",\n \"args3\": [\n {\n \"type\": \"field_label\",\n \"text\": \"data\"\n },\n {\n \"type\": \"input_value\",\n \"name\": \"data\"\n }\n ],\n \"colour\": \"#2e477d\"\n};\n\nwindow['Blockly'].Blocks['__ambient_ambientSend'] = {\n init: function() {\n this.jsonInit(__ambient_ambientSend_json);\n }\n};\n\nwindow['Blockly'].Python['__ambient_ambientSend'] = function(block) {\n var channelId = block.getFieldValue('channelId');\nvar writeKey = block.getFieldValue('writeKey');\nvar data = Blockly.Python.valueToCode(block, 'data', Blockly.Python.ORDER_NONE);\n return `import urequests\ndef ambientSend(_channelId, _writeKey, _data):\n if isinstance(_data, list):\n __d = _data\n else:\n __d = [_data]\n try:\n req = urequests.request(method='POST', url=((('http://ambidata.io/api/v2/channels/' + str(_channelId))) + '/dataarray'),json={'writeKey':_writeKey,'data':__d}, headers={'Content-Type':'application/json'})\n _ret = True\n except:\n _ret = False\n return _ret\n\nambientSend(${channelId}, ${writeKey}, ${data})\n` + \"\\n\";\n};\n\n","code":{"ambientSend":["window['Blockly'].Python['__ambient_ambientSend'] = function(block) {\n var channelId = block.getFieldValue('channelId');\nvar writeKey = block.getFieldValue('writeKey');\nvar data = Blockly.Python.valueToCode(block, 'data', Blockly.Python.ORDER_NONE);\n return `import urequests\ndef ambientSend(_channelId, _writeKey, _data):\n if isinstance(_data, list):\n __d = _data\n else:\n __d = [_data]\n try:\n req = urequests.request(method='POST', url=((('http://ambidata.io/api/v2/channels/' + str(_channelId))) + '/dataarray'),json={'writeKey':_writeKey,'data':__d}, headers={'Content-Type':'application/json'})\n _ret = True\n except:\n _ret = False\n return _ret\n\nambientSend(${channelId}, ${writeKey}, ${data})\n` + \"\\n\";\n};\n\n","import urequests\ndef ambientSend(_channelId, _writeKey, _data):\n if isinstance(_data, list):\n __d = _data\n else:\n __d = [_data]\n try:\n req = urequests.request(method='POST', url=((('http://ambidata.io/api/v2/channels/' + str(_channelId))) + '/dataarray'),json={'writeKey':_writeKey,'data':__d}, headers={'Content-Type':'application/json'})\n _ret = True\n except:\n _ret = False\n return _ret\n\nambientSend(${channelId}, ${writeKey}, ${data})\n"]}}