Advertisement
Guest User

Untitled

a guest
Apr 7th, 2023
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.48 KB | None | 0 0
  1. // Copyright (c) Microsoft. All rights reserved.
  2. // Licensed under the MIT license. See LICENSE file in the project root for full
  3. // license information.
  4.  
  5. #include <ESP8266WiFi.h>
  6. #include "src/iotc/common/string_buffer.h"
  7. #include "src/iotc/iotc.h"
  8.  
  9. #define WIFI_SSID "nazev"
  10. #define WIFI_PASSWORD "heslo"
  11.  
  12. const char* SCOPE_ID = "oborID";
  13. const char* DEVICE_ID = "ID";
  14. const char* DEVICE_KEY = "klíč";
  15.  
  16. void on_event(IOTContext ctx, IOTCallbackInfo* callbackInfo);
  17. #include "src/connection.h"
  18.  
  19. void on_event(IOTContext ctx, IOTCallbackInfo* callbackInfo) {
  20. // ConnectionStatus
  21. if (strcmp(callbackInfo->eventName, "ConnectionStatus") == 0) {
  22. LOG_VERBOSE("Is connected ? %s (%d)",
  23. callbackInfo->statusCode == IOTC_CONNECTION_OK ? "YES" : "NO",
  24. callbackInfo->statusCode);
  25. isConnected = callbackInfo->statusCode == IOTC_CONNECTION_OK;
  26. return;
  27. }
  28.  
  29. // payload buffer doesn't have a null ending.
  30. // add null ending in another buffer before print
  31. AzureIOT::StringBuffer buffer;
  32. if (callbackInfo->payloadLength > 0) {
  33. buffer.initialize(callbackInfo->payload, callbackInfo->payloadLength);
  34. }
  35.  
  36. LOG_VERBOSE("- [%s] event was received. Payload => %s\n",
  37. callbackInfo->eventName, buffer.getLength() ? *buffer : "EMPTY");
  38.  
  39. if (strcmp(callbackInfo->eventName, "Command") == 0) {
  40. LOG_VERBOSE("- Command name was => %s\r\n", callbackInfo->tag);
  41. }
  42. }
  43.  
  44. const int LED_PIN = 13;
  45. const int INTERRUPT_PIN = 2;
  46. int cas = 0;
  47. //unsigned long previousMillis = 0UL;
  48. //unsigned long interval = 1000UL;
  49.  
  50. void setup() {
  51. // put your setup code here, to run once:
  52. pinMode(LED_PIN, OUTPUT);
  53. pinMode(INTERRUPT_PIN, INPUT_PULLUP);
  54. attachInterrupt(digitalPinToInterrupt(INTERRUPT_PIN), resetcasovac, FALLING);
  55. Serial.begin(9600);
  56. return run();
  57. connect_wifi(WIFI_SSID, WIFI_PASSWORD);
  58. connect_client(SCOPE_ID, DEVICE_ID, DEVICE_KEY);
  59.  
  60. }
  61.  
  62. void loop() {
  63. // put your main code here, to run repeatedly
  64.  
  65. }
  66.  
  67. void run(){
  68.  
  69. for(cas; cas < 30;cas++){
  70. delay(1000);
  71. //unsigned long currentMillis = millis();
  72.  
  73. //if(currentMillis - previousMillis > interval)
  74. //{
  75. //cas++;
  76. //previousMillis = currentMillis;
  77. Serial.println(cas);
  78. //}
  79. if(cas>20){
  80. digitalWrite(LED_PIN, HIGH);
  81. }
  82.  
  83. }
  84. Serial.println("Tlacitko nezmacknuto.");
  85.  
  86. }
  87.  
  88. void resetcasovac(){
  89. cas = 0;
  90. digitalWrite(LED_PIN, LOW);
  91. Serial.println("Tlacitko zmacknuto.");
  92.  
  93.  
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement