Guest User

Untitled

a guest
May 26th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.13 KB | None | 0 0
  1. /*
  2. This example is meant to be used as a starting point
  3. for working with Anto.io services
  4.  
  5. 2017/06/17
  6. by Anto.io team
  7.  
  8. */
  9.  
  10. #include <AntoIO.h>
  11.  
  12. const char *ssid = "your access point SSID";
  13. const char *pass = "access point password";
  14. const char *user = "your username";
  15. const char *token = "your token";
  16. const char *thing = "your thing";
  17.  
  18. // initialize AntoIO instance
  19. AntoIO anto(user, token, thing);
  20.  
  21. int value = 0;
  22.  
  23. void setup() {
  24. Serial.begin(115200);
  25. delay(10);
  26.  
  27. Serial.println();
  28. Serial.println();
  29. Serial.print("Anto library version: ");
  30. Serial.println(anto.getVersion());
  31.  
  32.  
  33. Serial.print("\nTrying to connect ");
  34. Serial.print(ssid);
  35. Serial.println("...");
  36.  
  37. anto.begin(ssid, pass, messageReceived);
  38. Serial.println("\nConnected Anto done");
  39.  
  40. //Subscript Channels
  41. anto.sub("all");
  42. anto.sub("led1");
  43. anto.sub("led2");
  44. anto.sub("led3");
  45. anto.sub("led4");
  46. //Port output
  47. pinMode(D1, OUTPUT);
  48. pinMode(D2, OUTPUT);
  49. pinMode(D3, OUTPUT);
  50. pinMode(D4, OUTPUT);
  51. }
  52.  
  53. void loop() {
  54. anto.mqtt.loop();
  55. }
  56.  
  57.  
  58. // a callback function for arriving data.
  59. void messageReceived(String thing, String channel, String payload) {
  60.  
  61. Serial.print("Recieved: ");
  62. Serial.print(thing);
  63. Serial.print("/");
  64. Serial.print(channel);
  65. Serial.print("-> ");
  66. Serial.println(payload);
  67.  
  68. if (channel.equals("led1")) {
  69. value = payload.toInt();
  70. if (value == 1) {
  71. digitalWrite(D1, HIGH);
  72. }
  73. else {
  74. digitalWrite(D1, LOW);
  75. }
  76.  
  77. }
  78. else if (channel.equals("led2")) {
  79. value = payload.toInt();
  80. if (value == 1) {
  81. digitalWrite(D2, HIGH);
  82. }
  83. else {
  84. digitalWrite(D2, LOW);
  85. }
  86. }
  87. else if (channel.equals("led3")) {
  88. value = payload.toInt();
  89. if (value == 1) {
  90. digitalWrite(D3 HIGH);
  91. }
  92. else {
  93. digitalWrite(D3, LOW);
  94. }
  95. }
  96. else if (channel.equals("all")) {
  97. value = payload.toInt();
  98. if (value == 1) {
  99. digitalWrite(D4, HIGH);
  100. digitalWrite(D3, HIGH);
  101. digitalWrite(D2, HIGH);
  102. digitalWrite(D1, HIGH);
  103. }
  104. else {
  105. digitalWrite(D4, LOW);
  106. digitalWrite(D3, LOW);
  107. digitalWrite(D2, LOW);
  108. digitalWrite(D1, LOW);
  109. }
  110. }
  111. }
Add Comment
Please, Sign In to add comment