Skip to content

Instantly share code, notes, and snippets.

View suru-dissanaike's full-sized avatar

Suru Dissanaike suru-dissanaike

View GitHub Profile
@suru-dissanaike
suru-dissanaike / gist:56f4f76d611db41a8b7736d316ada119
Created August 21, 2018 08:31
Simple MQTT subscribe example using the Eclipse Paho Java Client
import org.eclipse.paho.client.mqttv3.MqttClient;
import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
import org.eclipse.paho.client.mqttv3.MqttException;
import org.eclipse.paho.client.mqttv3.MqttMessage;
import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken;
import org.eclipse.paho.client.mqttv3.MqttCallback;
public class HelloMQTT implements MqttCallback {
MqttClient client;
private MqttConnectOptions conOpt;
@suru-dissanaike
suru-dissanaike / .js
Created January 25, 2019 16:10
BLE pushbutton with counter
var blueLEDOn = false;
var pushbuttonCounter = 0;
setInterval(function () {
blueLEDOn = !blueLEDOn;
LED3.write(blueLEDOn);
}, 1000);
@suru-dissanaike
suru-dissanaike / .json
Last active January 26, 2019 18:56
Visual Studio Code settings c & cpp
[{
"C_Cpp.intelliSenseEngineFallback": "Enabled",
"files.associations": {
"mgos.h": "c"
},
"C_Cpp.intelliSenseEngine": "Tag Parser"
}]
@suru-dissanaike
suru-dissanaike / .json
Created January 26, 2019 18:58
Visual Studio Code includePath
[{
"includePath": [
"${workspaceFolder}/**",
"/your path/git/mongoose-os/",
"/your path/git/esp-idf/",
"/your path/git/mjs/"
]
}]
@suru-dissanaike
suru-dissanaike / .c
Created January 26, 2019 19:00
mgos_adc_enable
bool mgos_adc_enable(int pin) {
 struct esp32_adc_channel_info *ci = esp32_adc_get_channel_info(pin);
 if (ci == NULL) return false;
/* TODO(rojer): Allow changing? */
 ci->atten = ADC_ATTEN_11db;
return esp32_update_channel_settings(ci);
}
@suru-dissanaike
suru-dissanaike / .h
Created January 26, 2019 19:00
Espressif Systems adc.h
typedef enum {
 ADC_ATTEN_DB_0 = 0, /*!<The input voltage of ADC will be reduced to about 1/1 */
 ADC_ATTEN_DB_2_5 = 1, /*!<The input voltage of ADC will be reduced to about 1/1.34 */
 ADC_ATTEN_DB_6 = 2, /*!<The input voltage of ADC will be reduced to about 1/2 */
 ADC_ATTEN_DB_11 = 3, /*!<The input voltage of ADC will be reduced to about 1/3.6*/
 ADC_ATTEN_MAX,
} adc_atten_t;
@suru-dissanaike
suru-dissanaike / .js
Created January 26, 2019 19:01
Mongoose JavaScript example ADC driver
let MYADC = {
 cfg: ffi('int adc1_config_channel_atten(int, int)'), // that function must be in the SDK
};
let db6 = 2; // whatever the numeric value for 6 dB is 2
MYADC.cfg(pin, db6);
@suru-dissanaike
suru-dissanaike / .c
Created January 26, 2019 19:03
Custom configuration of the ADC
#include <stdio.h>
#include "esp32/esp32_adc.h"
#include "esp_adc_cal.h"
#include "mgos.h"
#include "mgos_adc.h"
#include "mgos_system.h"
[Feb 13 20:51:19.925] mgos_app_init        c-code dual core ver 0.1
[Feb 13 20:51:19.925] mgos_app_init        CPU Speed: 240 
[Feb 13 20:51:19.925] mgos_app_init        Interrupt attached
[Feb 13 20:51:21.942] task_toggle_led      core: 1task_other_core      
[Feb 13 20:51:21.942] mgos_app_init        core: 0app_init done
[Feb 13 20:51:21.942] 
[Feb 13 20:51:21.942] mgos_init            Init done, RAM: 307692 total, 267056 free, 267056 min free
[Feb 13 20:51:22.934] mongoose_poll        New heap free LWM: 267016
[Feb 13 20:51:26.005] interupt_handler_gpi core: 0
import obd
connection = obd.OBD("/dev/rfcomm0")
cmd = obd.commands.RPM
response = connection.query(cmd)
print(response.value)
print(connection.protocol_name())