├── Actuator └── init.js ├── Models ├── wifibutton.blend └── wifibutton.stl ├── README.md ├── fs └── init.js └── mos.yml /Actuator/init.js: -------------------------------------------------------------------------------- 1 | load('api_config.js'); 2 | load('api_gpio.js'); 3 | load('api_mqtt.js'); 4 | load('api_sys.js'); 5 | load('api_timer.js'); 6 | load("api_pwm.js"); 7 | 8 | //*********************************************** 9 | //io.adafruit mqtt settings and set feed name here: 10 | let feedName = 'wifiButton01'; 11 | //*********************************************** 12 | let D1 = 5; 13 | let subbed = false; 14 | 15 | //trying mqtt 16 | MQTT.setEventHandler(function(conn, ev, edata) 17 | { 18 | if (ev === MQTT.EV_CONNACK && !subbed) 19 | { 20 | print('subbing mqtt'); 21 | let topic = Cfg.get('mqtt.user') + '/feeds/' + feedName; 22 | MQTT.sub(topic, function(conn, topic, msg){ 23 | print('new value ' + topic + ' ' + msg); 24 | action(); 25 | }); 26 | subbed = true; 27 | } 28 | }, null); 29 | 30 | function action() 31 | { 32 | print('moving servo'); 33 | GPIO.set_mode(D1, GPIO.MODE_OUTPUT); 34 | //move to position 0 35 | PWM.set(D1, 50, 10); 36 | //wait for servo 37 | Timer.set(1000, false , function() { 38 | //turn off servo 39 | PWM.set(D1, 50, 0); 40 | //wait a sec 41 | Timer.set(1000, false , function() { 42 | //move to position 1 43 | PWM.set(D1, 50, 1); 44 | //wait for servo 45 | Timer.set(1000, false , function() { 46 | //turn off 47 | PWM.set(D1, 50, 0); 48 | print('servo off'); 49 | }, null); 50 | }, null); 51 | }, null); 52 | } 53 | -------------------------------------------------------------------------------- /Models/wifibutton.blend: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mongoose-os-apps/smallest-wifi-button/0193671993134361a465a5b4e7b8941d41747056/Models/wifibutton.blend -------------------------------------------------------------------------------- /Models/wifibutton.stl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mongoose-os-apps/smallest-wifi-button/0193671993134361a465a5b4e7b8941d41747056/Models/wifibutton.stl -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # The Smallest WiFi Button in the World (ESP8266, MQTT, IFTTT) 2 | 3 | [![youtube video](https://img.youtube.com/vi/ImVK5cGVrpQ/0.jpg)](https://www.youtube.com/watch?v=ImVK5cGVrpQ) 4 | 5 | This is some code for a WiFi-Button project using Mongoose OS 6 | After flashing Mongoose on your microcontroller simply 7 | replace the contents of the init.js with the corresponding file. 8 | The button uses a direct link or mqtt. 9 | The Actuator simply moves a servo connected to D1(aon WemMos MCU) 10 | 11 | License: 12 | 13 | The contents of this repository are licenced under cc-by 14 | https://creativecommons.org/licenses/by/4.0/deed.de 15 | 16 | This means you can use the stuff even commercially as long you attribute me. 17 | For attribution please use bitluni and the link https://youtube.com/bitlunislab 18 | 19 | have fun! 20 | -------------------------------------------------------------------------------- /fs/init.js: -------------------------------------------------------------------------------- 1 | load('api_config.js'); 2 | load('api_gpio.js'); 3 | load('api_mqtt.js'); 4 | load('api_sys.js'); 5 | load('api_timer.js'); 6 | load("api_esp8266.js"); 7 | load('api_http.js'); 8 | 9 | //*********************************************** 10 | //put the link in the quotes if using request... 11 | let requestUrl = ''; 12 | 13 | //...or set io.adafruit mqtt settings and set feed name here: 14 | let feedName = 'wifiButton01'; 15 | 16 | //some millisecond settings. adjust to your needs 17 | let millisToTurnOff = 60000; 18 | //*********************************************** 19 | 20 | // 21 | Timer.set(millisToTurnOff , false , function() { 22 | print("deep sleep"); 23 | ESP8266.deepSleep(0); 24 | }, null); 25 | 26 | if(requestUrl.length > 0) 27 | { 28 | //request url not empty so invoke it 29 | Net.setStatusEventHandler(function(ev, edata){ 30 | if(ev !== Net.STATUS_GOT_IP) return; 31 | print("httpRequest"); 32 | HTTP.query({ 33 | url: requestUrl, 34 | success: function(){ 35 | print('HTTP request sent'); 36 | }, 37 | error: function(){ 38 | print('HTTP request failed'); 39 | } 40 | }); 41 | Net.setStatusEventHandler(function(){}, null); 42 | }, null); 43 | } 44 | 45 | //trying mqtt 46 | MQTT.setEventHandler(function(conn, ev, edata) 47 | { 48 | if (ev === MQTT.EV_CONNACK) 49 | { 50 | let topic = Cfg.get('mqtt.user') + '/feeds/' + feedName; 51 | let ok = MQTT.pub(topic, JSON.stringify(1), 1); 52 | if(ok) print('sent mqtt') 53 | else print('failed mqtt'); 54 | MQTT.setEventHandler(function(){}, null); 55 | } 56 | }, null); 57 | -------------------------------------------------------------------------------- /mos.yml: -------------------------------------------------------------------------------- 1 | author: bitluni 2 | description: The Smallest WiFi Button in the World (ESP8266, MQTT, IFTTT) 3 | version: 1.0 4 | platform: esp8266 5 | 6 | libs_version: ${mos.version} 7 | modules_version: ${mos.version} 8 | mongoose_os_version: ${mos.version} 9 | 10 | tags: 11 | - js 12 | 13 | filesystem: 14 | - fs 15 | 16 | libs: 17 | - origin: https://github.com/mongoose-os-libs/js-demo-bundle 18 | 19 | build_vars: 20 | FLASH_SIZE: 1048576 21 | 22 | manifest_version: 2017-05-18 23 | --------------------------------------------------------------------------------