Advertisement
rtcv

Untitled

Apr 24th, 2024
732
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.36 KB | None | 0 0
  1. /****************************************
  2.  * Include Libraries
  3.  ****************************************/
  4. #include "UbidotsESPMQTT.h"
  5.  
  6. /****************************************
  7.  * Define Constants
  8.  ****************************************/
  9. #define TOKEN "" // Your Ubidots TOKEN
  10. #define WIFINAME "" //Your SSID
  11. #define WIFIPASS "" // Your Wifi Pass
  12.  
  13. Ubidots client(TOKEN);
  14.  
  15. /****************************************
  16.  * Auxiliar Functions
  17.  ****************************************/
  18.  
  19. void callback(char* topic, byte* payload, unsigned int length) {
  20.   Serial.print("Message arrived [");
  21.   Serial.print(topic);
  22.   Serial.print("] ");
  23.   for (int i=0;i<length;i++) {
  24.     Serial.print((char)payload[i]);
  25.   }
  26.   Serial.println();
  27. }
  28.  
  29. /****************************************
  30.  * Main Functions
  31.  ****************************************/
  32.  
  33. void setup() {
  34.   // put your setup code here, to run once:
  35.   client.setDebug(true); // Pass a true or false bool value to activate debug messages
  36.   Serial.begin(115200);
  37.   client.wifiConnection(WIFINAME, WIFIPASS);
  38.   client.begin(callback);
  39.   }
  40.  
  41. void loop() {
  42.   // put your main code here, to run repeatedly:
  43.   if(!client.connected()){
  44.     client.reconnect();
  45.   }
  46.  
  47.   float heartBeat = analogRead(A0);
  48.   client.add("heart-beat", heartBeat);
  49.   client.ubidotsPublish("demo-machine");
  50.   client.loop();
  51.   delay(1000);
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement