evenjc

Blynk - Read/Write Example

May 11th, 2022
2,430
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*************************************************************
  2.  
  3.   You’ll need:
  4.    - Blynk IoT app (download from App Store or Google Play)
  5.    - ESP32 board
  6.    - Decide how to connect to Blynk
  7.      (USB, Ethernet, Wi-Fi, Bluetooth, ...)
  8.  
  9.   There is a bunch of great example sketches included to show you how to get
  10.   started. Think of them as LEGO bricks  and combine them as you wish.
  11.   For example, take the Ethernet Shield sketch and combine it with the
  12.   Servo example, or choose a USB sketch and add a code from SendData
  13.   example.
  14.  *************************************************************/
  15.  
  16. // Template ID, Device Name and Auth Token are provided by the Blynk.Cloud
  17. // See the Device Info tab, or Template settings
  18. #define BLYNK_TEMPLATE_ID "TMPLDTK7VdBa"
  19. #define BLYNK_DEVICE_NAME "Quickstart Template"
  20. #define BLYNK_AUTH_TOKEN "XPz_Xh-4UZCPlTw4kMsyWSAYFyP-Egli"
  21.  
  22.  
  23. // Comment this out to disable prints and save space
  24. #define BLYNK_PRINT Serial
  25.  
  26.  
  27. #include <WiFi.h>
  28. #include <WiFiClient.h>
  29. #include <BlynkSimpleEsp32.h>
  30.  
  31. char auth[] = BLYNK_AUTH_TOKEN;
  32.  
  33. long randNumber;
  34.  
  35. // Your WiFi credentials.
  36. // Set password to "" for open networks.
  37. char ssid[] = "hideyowifi";
  38. char pass[] = "hideyokids";
  39.  
  40. /* ------------ */
  41. BlynkTimer timer;
  42.  
  43. BLYNK_WRITE(V6) {
  44.   int pinValue = param.asInt();
  45.  
  46.   Serial.print("Vi fikk endring på: ");
  47.   Serial.println(pinValue);
  48. }
  49.  
  50. void myTimedEvent() {
  51.   int _data = random(0, 255);
  52.   Serial.print("Sender ");
  53.   Serial.print(_data);
  54.   Serial.println(" til Blynk");
  55.  
  56.   Blynk.virtualWrite(V7, _data);
  57. }
  58.  
  59. /* ------------ */
  60. void setup()
  61. {
  62.   // Debug console
  63.   Serial.begin(115200);
  64.   randomSeed(analogRead(0));
  65.   Blynk.begin(auth, ssid, pass);
  66.   timer.setInterval(1000UL, myTimedEvent);
  67.   // You can also specify server:
  68.   //Blynk.begin(auth, ssid, pass, "blynk.cloud", 80);
  69.   //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);
  70. }
  71.  
  72. void loop()
  73. {
  74.   Blynk.run();
  75.   timer.run();
  76.   // You can inject your own code or combine it with other sketches.
  77.   // Check other examples on how to communicate with Blynk. Remember
  78.   // to avoid delay() function!
  79. }
  80.  
Advertisement
Add Comment
Please, Sign In to add comment