add services
This commit is contained in:
parent
fe328f9da3
commit
9318d3ef12
@ -13,7 +13,8 @@ Blockly.Blocks["sensebox_mqtt_setup"] = {
|
|||||||
this.setHelpUrl('');
|
this.setHelpUrl('');
|
||||||
this.setColour(getColour().mqtt);
|
this.setColour(getColour().mqtt);
|
||||||
this.appendDummyInput()
|
this.appendDummyInput()
|
||||||
.appendField(Blockly.Msg.senseBox_mqtt_init);
|
.appendField(Blockly.Msg.senseBox_mqtt_init)
|
||||||
|
.appendField(new Blockly.FieldDropdown([["Adafruit IO", 'adafruitio'], ["DIOTY", 'dioty'], ["Other Service", 'custom']]), "service");
|
||||||
this.appendDummyInput()
|
this.appendDummyInput()
|
||||||
.setAlign(Blockly.ALIGN_LEFT)
|
.setAlign(Blockly.ALIGN_LEFT)
|
||||||
.appendField(Blockly.Msg.senseBox_mqtt_server)
|
.appendField(Blockly.Msg.senseBox_mqtt_server)
|
||||||
@ -28,10 +29,34 @@ Blockly.Blocks["sensebox_mqtt_setup"] = {
|
|||||||
.appendField(new Blockly.FieldTextInput("Username"), "username");
|
.appendField(new Blockly.FieldTextInput("Username"), "username");
|
||||||
this.appendDummyInput()
|
this.appendDummyInput()
|
||||||
.setAlign(Blockly.ALIGN_LEFT)
|
.setAlign(Blockly.ALIGN_LEFT)
|
||||||
.appendField(Blockly.Msg.senseBox_mqtt_password)
|
.appendField(Blockly.Msg.senseBox_mqtt_password, "passwordmsg")
|
||||||
.appendField(new Blockly.FieldTextInput("Password"), "password");
|
.appendField(new Blockly.FieldTextInput("Password"), "password");
|
||||||
this.setPreviousStatement(true, null);
|
this.setPreviousStatement(true, null);
|
||||||
this.setNextStatement(true, null);
|
this.setNextStatement(true, null);
|
||||||
|
},
|
||||||
|
onchange: function (e) {
|
||||||
|
let service = this.getFieldValue('service');
|
||||||
|
switch (this.getFieldValue('service')) {
|
||||||
|
case 'adafruitio':
|
||||||
|
this.getField('server').setValue("io.adafruit.com");
|
||||||
|
this.getField('port').setValue("1883");
|
||||||
|
this.getField('passwordmsg').setValue("Adafruit IO Key");
|
||||||
|
break;
|
||||||
|
case 'dioty':
|
||||||
|
this.getField('server').setValue("mqtt.dioty.co");
|
||||||
|
this.getField('port').setValue("1883");
|
||||||
|
this.getField('passwordmsg').setValue(Blockly.Msg.senseBox_mqtt_password);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "custom":
|
||||||
|
this.getField('server').setValue("server");
|
||||||
|
this.getField('port').setValue("port");
|
||||||
|
this.getField('passwordmsg').setValue(Blockly.Msg.senseBox_mqtt_password);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -3,11 +3,14 @@ import * as Blockly from 'blockly/core';
|
|||||||
* MQTT Blocks
|
* MQTT Blocks
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
let service;
|
||||||
|
|
||||||
Blockly.Arduino.sensebox_mqtt_setup = function () {
|
Blockly.Arduino.sensebox_mqtt_setup = function () {
|
||||||
var server = this.getFieldValue('server');
|
var server = this.getFieldValue('server');
|
||||||
var port = this.getFieldValue('port');
|
var port = this.getFieldValue('port');
|
||||||
var username = this.getFieldValue('username');
|
var username = this.getFieldValue('username');
|
||||||
var pass = this.getFieldValue('password');
|
var pass = this.getFieldValue('password');
|
||||||
|
service = this.getFieldValue('service');
|
||||||
Blockly.Arduino.libraries_['library_senseBoxMCU'] = '#include "SenseBoxMCU.h"';
|
Blockly.Arduino.libraries_['library_senseBoxMCU'] = '#include "SenseBoxMCU.h"';
|
||||||
Blockly.Arduino.libraries_['library_adafruitmqtt'] = '#include "Adafruit_MQTT.h"';
|
Blockly.Arduino.libraries_['library_adafruitmqtt'] = '#include "Adafruit_MQTT.h"';
|
||||||
Blockly.Arduino.libraries_['library_adafruitmqttclient'] = '#include "Adafruit_MQTT_Client.h"';
|
Blockly.Arduino.libraries_['library_adafruitmqttclient'] = '#include "Adafruit_MQTT_Client.h"';
|
||||||
@ -26,7 +29,23 @@ Blockly.Arduino.sensebox_mqtt_publish = function (block) {
|
|||||||
var res = feedname.split("/");
|
var res = feedname.split("/");
|
||||||
var feed_client = res[res.length - 1];
|
var feed_client = res[res.length - 1];
|
||||||
var value = Blockly.Arduino.valueToCode(this, 'value', Blockly.Arduino.ORDER_ATOMIC) || '"No Block connected"';
|
var value = Blockly.Arduino.valueToCode(this, 'value', Blockly.Arduino.ORDER_ATOMIC) || '"No Block connected"';
|
||||||
Blockly.Arduino.definitions_['mqtt_' + feed_client + ''] = 'Adafruit_MQTT_Publish ' + feed_client + ' = Adafruit_MQTT_Publish(&mqtt, USERNAME "/feeds/' + feedname + '");'
|
|
||||||
|
switch (service) {
|
||||||
|
case 'adafruitio':
|
||||||
|
Blockly.Arduino.definitions_['mqtt_' + feed_client + ''] = 'Adafruit_MQTT_Publish ' + feed_client + ' = Adafruit_MQTT_Publish(&mqtt, USERNAME "/feeds/' + feedname + '");'
|
||||||
|
break;
|
||||||
|
case 'dioty':
|
||||||
|
Blockly.Arduino.definitions_['mqtt_' + feed_client + ''] = 'Adafruit_MQTT_Publish ' + feed_client + ' = Adafruit_MQTT_Publish(&mqtt, "/"USERNAME"/' + feedname + '");'
|
||||||
|
break;
|
||||||
|
case 'custom':
|
||||||
|
Blockly.Arduino.definitions_['mqtt_' + feed_client + ''] = 'Adafruit_MQTT_Publish ' + feed_client + ' = Adafruit_MQTT_Publish(&mqtt, ' + feedname + ');'
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//Blockly.Arduino.definitions_['mqtt_' + feed_client + ''] = 'Adafruit_MQTT_Publish ' + feed_client + ' = Adafruit_MQTT_Publish(&mqtt, USERNAME "/feeds/' + feedname + '");'
|
||||||
Blockly.Arduino.codeFunctions_['mqtt_connect_function'] = `// Function to connect and reconnect as necessary to the MQTT server.
|
Blockly.Arduino.codeFunctions_['mqtt_connect_function'] = `// Function to connect and reconnect as necessary to the MQTT server.
|
||||||
// Should be called in the loop function and it will take care if connecting.
|
// Should be called in the loop function and it will take care if connecting.
|
||||||
void MQTT_connect() {
|
void MQTT_connect() {
|
||||||
|
@ -785,7 +785,7 @@ Blockly.Msg.senseBox_ws2818_rgb_led_brightness = "Helligkeit";
|
|||||||
* MQTT
|
* MQTT
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Blockly.Msg.senseBox_mqtt_init = "Initialisiere MQTT Broker";
|
Blockly.Msg.senseBox_mqtt_init = "Verbinde mit MQTT Broker";
|
||||||
Blockly.Msg.senseBox_mqtt_server = "Server";
|
Blockly.Msg.senseBox_mqtt_server = "Server";
|
||||||
Blockly.Msg.senseBox_mqtt_port = "Port";
|
Blockly.Msg.senseBox_mqtt_port = "Port";
|
||||||
Blockly.Msg.senseBox_mqtt_username = "Benutzername";
|
Blockly.Msg.senseBox_mqtt_username = "Benutzername";
|
||||||
|
@ -767,7 +767,7 @@ Blockly.Msg.senseBox_ws2818_rgb_led_position = "Position";
|
|||||||
* MQTT
|
* MQTT
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Blockly.Msg.senseBox_mqtt_init = "Initialize MQTT Broker";
|
Blockly.Msg.senseBox_mqtt_init = "Connect to MQTT Broker";
|
||||||
Blockly.Msg.senseBox_mqtt_server = "Server";
|
Blockly.Msg.senseBox_mqtt_server = "Server";
|
||||||
Blockly.Msg.senseBox_mqtt_port = "Port";
|
Blockly.Msg.senseBox_mqtt_port = "Port";
|
||||||
Blockly.Msg.senseBox_mqtt_username = "Username";
|
Blockly.Msg.senseBox_mqtt_username = "Username";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user