├── .gitattributes └── 4ch_relay_esp01 └── 4ch_relay_esp01.ino /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /4ch_relay_esp01/4ch_relay_esp01.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * This is the code for the project 3 | * "Internet & Manual Controlled 4ch Automation' 4 | * which is Uploaded on techiesms YouTube Channel 5 | * 6 | * You can watch the full tutorial from here 7 | * https://youtu.be/tvZ0XZWYe8U 8 | * 9 | * 10 | * techiesms 11 | * explore | learn | share 12 | * 13 | */ 14 | 15 | /**************************************** 16 | Include Libraries 17 | ****************************************/ 18 | #include "UbidotsESPMQTT.h" // Download the libray from here https://github.com/ubidots/ubidots-mqtt-esp 19 | 20 | /**************************************** 21 | Define Constants 22 | ****************************************/ 23 | #define WIFINAME "SmS_jiofi" //Your SSID 24 | #define WIFIPASS "sms123458956" // Your Wifi Pass 25 | #define TOKEN "BBFF-4eoB0mUpfvAgV8RD9DRLTg1iE0Z5Kt" // Your Ubidots TOKEN 26 | 27 | 28 | #define r1 0 29 | #define r2 1 30 | #define r3 2 31 | #define r4 3 32 | 33 | 34 | Ubidots client(TOKEN); 35 | 36 | /**************************************** 37 | Auxiliar Functions 38 | ****************************************/ 39 | 40 | void callback(char* topic, byte* payload, unsigned int length) { 41 | 42 | if ((String)topic == "/v1.6/devices/esp-01/r1/lv") 43 | { 44 | int mytopic = atoi(topic); 45 | payload[length] = '\0'; 46 | int mymsg = atoi ((const char*)payload); 47 | 48 | int val1 = mymsg; 49 | digitalWrite(r1, val1); 50 | } 51 | 52 | else if ((String)topic == "/v1.6/devices/esp-01/r2/lv") 53 | { 54 | 55 | int mytopic = atoi(topic); 56 | payload[length] = '\0'; 57 | int mymsg = atoi ((const char*)payload); 58 | 59 | int val1 = mymsg; 60 | digitalWrite(r2, val1); 61 | } 62 | else if ((String)topic == "/v1.6/devices/esp-01/r3/lv") 63 | { 64 | 65 | int mytopic = atoi(topic); 66 | payload[length] = '\0'; 67 | int mymsg = atoi ((const char*)payload); 68 | 69 | int val1 = mymsg; 70 | digitalWrite(r3, val1); 71 | } 72 | else if ((String)topic == "/v1.6/devices/esp-01/r4/lv") 73 | { 74 | 75 | int mytopic = atoi(topic); 76 | payload[length] = '\0'; 77 | int mymsg = atoi ((const char*)payload); 78 | 79 | int val1 = mymsg; 80 | digitalWrite(r4, val1); 81 | } 82 | else 83 | {} 84 | } 85 | //Serial.println(); 86 | 87 | /**************************************** 88 | Main Functions 89 | ****************************************/ 90 | 91 | void setup() { 92 | // put your setup code here, to run once: 93 | client.ubidotsSetBroker("business.api.ubidots.com"); // Sets the broker properly for the business account 94 | client.setDebug(true); // Pass a true or false bool value to activate debug messages 95 | client.wifiConnection(WIFINAME, WIFIPASS); 96 | pinMode(r1, OUTPUT); 97 | pinMode(r2, OUTPUT); 98 | pinMode(r3, OUTPUT); 99 | pinMode(r4, OUTPUT); 100 | digitalWrite(r1, HIGH); 101 | digitalWrite(r2, HIGH); 102 | digitalWrite(r3, HIGH); 103 | digitalWrite(r4, HIGH); 104 | client.begin(callback); 105 | client.ubidotsSubscribe("esp-01", "r1"); //Insert the dataSource and Variable's Labels 106 | client.ubidotsSubscribe("esp-01", "r2"); //Insert the dataSource and Variable's Labels 107 | client.ubidotsSubscribe("esp-01", "r3"); //Insert the dataSource and Variable's Labels 108 | client.ubidotsSubscribe("esp-01", "r4"); //Insert the dataSource and Variable's Labels 109 | } 110 | 111 | void loop() { 112 | // put your main code here, to run repeatedly: 113 | if (!client.connected()) { 114 | client.reconnect(); 115 | client.ubidotsSubscribe("esp-01", "r1"); //Insert the dataSource and Variable's Labels 116 | client.ubidotsSubscribe("esp-01", "r2"); //Insert the dataSource and Variable's Labels 117 | client.ubidotsSubscribe("esp-01", "r3"); //Insert the dataSource and Variable's Labels 118 | client.ubidotsSubscribe("esp-01", "r4"); //Insert the dataSource and Variable's Labels 119 | } 120 | client.loop(); 121 | } 122 | --------------------------------------------------------------------------------