Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
en:iot:examples:rgb [2021/03/04 23:26] heiko.pikneren:iot:examples:rgb [Unknown date] (current) – external edit (Unknown date) 127.0.0.1
Line 11: Line 11:
 The example code above lights the RGB LED The example code above lights the RGB LED
 <code c> <code c>
-// Includes global variables and librarys that the RGB LED uses 
 #include <Arduino.h> #include <Arduino.h>
 #include <ittiot.h> #include <ittiot.h>
 #include <Adafruit_NeoPixel.h> #include <Adafruit_NeoPixel.h>
 +
 +#define MODULE_TOPIC "ESP30/rgb"
 +#define WIFI_NAME "name"
 +#define WIFI_PASSWORD "password"
  
 //Stating, to which PIN the RGB LED has been connected //Stating, to which PIN the RGB LED has been connected
Line 40: Line 43:
         strIndex[1] = (i == maxIndex) ? i+1 : i;         strIndex[1] = (i == maxIndex) ? i+1 : i;
     }     }
-  } +  }
   return found>index ? data.substring(strIndex[0], strIndex[1]) : "";   return found>index ? data.substring(strIndex[0], strIndex[1]) : "";
 } }
Line 52: Line 55:
   Serial.print(" payload: ");   Serial.print(" payload: ");
   Serial.println(msg);   Serial.println(msg);
-  // Splitting the RGB values into smaller parts 
-  String r = getValue(msg,';',0); 
-  String g = getValue(msg,';',1); 
-  String b = getValue(msg,';',2); 
  
-  Serial.print("R: "); +  if(topic == MODULE_TOPIC) 
-  Serial.println(r);+  { 
 +    // Splitting the RGB values into smaller parts 
 +    String r = getValue(msg,';',0); 
 +    String g = getValue(msg,';',1); 
 +    String b = getValue(msg,';',2); 
 + 
 +    Serial.print("R: "); 
 +    Serial.println(r);
  
-  Serial.print("G: "); +    Serial.print("G: "); 
-  Serial.println(g);+    Serial.println(g);
  
-  Serial.print("B: "); +    Serial.print("B: "); 
-  Serial.println(b);+    Serial.println(b);
  
-  // Sending the color code to the RGB LED +    // Sending the color code to the RGB LED 
-  pixels.setPixelColor(0, r.toInt(), g.toInt(), b.toInt()); // Moderately bright green color. The 0 number addresses the first RGB LED (is the address number) +    pixels.setPixelColor(0, r.toInt(), g.toInt(), b.toInt()); // Moderately bright green color. The 0 number addresses the first RGB LED (is the address number) 
-  pixels.show(); // This sends the updated pixel color to the hardware.+    pixels.show(); // This sends the updated pixel color to the hardware. 
 +  }
 } }
  
Line 75: Line 82:
 { {
   Serial.println("MQTT connected callback");   Serial.println("MQTT connected callback");
-  iot.subscribe("ESP01/rgb");+  iot.subscribe(MODULE_TOPIC);
   iot.log("IoT NeoPixel example!");   iot.log("IoT NeoPixel example!");
 } }
Line 85: Line 92:
   Serial.println("Booting");   Serial.println("Booting");
  
 +  //iot.setConfig("wname", WIFI_NAME);
 +  //iot.setConfig("wpass", WIFI_PASSWORD);
   iot.printConfig(); // print json config to serial   iot.printConfig(); // print json config to serial
   iot.setup();   iot.setup();
Line 97: Line 106:
   delay(200); // Delay of 200 ms   delay(200); // Delay of 200 ms
 } }
 +
 </code> </code>
en/iot/examples/rgb.1614900371.txt.gz · Last modified: 2021/03/04 10:00 (external edit)
CC Attribution-Share Alike 4.0 International
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0