Advertisement
Guest User

Untitled

a guest
Mar 30th, 2020
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. #include <SPI.h>
  2. #include <Ethernet.h>
  3. #include <PubSubClient.h>
  4.  
  5. // Update these with values suitable for your network.
  6. byte mac[] = { 0xDE, 0xED, 0xBA, 0xFE, 0xFE, 0xED };
  7. IPAddress ip(172, 16, 0, 100);
  8. IPAddress server(172, 16, 0, 2);
  9.  
  10. void callback(char* topic, byte* payload, unsigned int length) {
  11. // handle message arrived
  12. }
  13.  
  14. EthernetClient ethClient;
  15. PubSubClient client(server, 1883, callback, ethClient);
  16.  
  17. void setup()
  18. {
  19. Ethernet.begin(mac, ip);
  20. if (client.connect("arduinoClient", "testuser", "testpass")) {
  21. client.publish("outTopic","hello world");
  22. client.subscribe("inTopic");
  23. }
  24. }
  25.  
  26. void loop()
  27. {
  28. client.loop();
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement