Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Copyright (c) Microsoft. All rights reserved.
- // Licensed under the MIT license. See LICENSE file in the project root for full
- // license information.
- #include <ESP8266WiFi.h>
- #include "src/iotc/common/string_buffer.h"
- #include "src/iotc/iotc.h"
- #define WIFI_SSID "nazev"
- #define WIFI_PASSWORD "heslo"
- const char* SCOPE_ID = "oborID";
- const char* DEVICE_ID = "ID";
- const char* DEVICE_KEY = "klíč";
- void on_event(IOTContext ctx, IOTCallbackInfo* callbackInfo);
- #include "src/connection.h"
- void on_event(IOTContext ctx, IOTCallbackInfo* callbackInfo) {
- // ConnectionStatus
- if (strcmp(callbackInfo->eventName, "ConnectionStatus") == 0) {
- LOG_VERBOSE("Is connected ? %s (%d)",
- callbackInfo->statusCode == IOTC_CONNECTION_OK ? "YES" : "NO",
- callbackInfo->statusCode);
- isConnected = callbackInfo->statusCode == IOTC_CONNECTION_OK;
- return;
- }
- // payload buffer doesn't have a null ending.
- // add null ending in another buffer before print
- AzureIOT::StringBuffer buffer;
- if (callbackInfo->payloadLength > 0) {
- buffer.initialize(callbackInfo->payload, callbackInfo->payloadLength);
- }
- LOG_VERBOSE("- [%s] event was received. Payload => %s\n",
- callbackInfo->eventName, buffer.getLength() ? *buffer : "EMPTY");
- if (strcmp(callbackInfo->eventName, "Command") == 0) {
- LOG_VERBOSE("- Command name was => %s\r\n", callbackInfo->tag);
- }
- }
- const int LED_PIN = 13;
- const int INTERRUPT_PIN = 2;
- int cas = 0;
- //unsigned long previousMillis = 0UL;
- //unsigned long interval = 1000UL;
- void setup() {
- // put your setup code here, to run once:
- pinMode(LED_PIN, OUTPUT);
- pinMode(INTERRUPT_PIN, INPUT_PULLUP);
- attachInterrupt(digitalPinToInterrupt(INTERRUPT_PIN), resetcasovac, FALLING);
- Serial.begin(9600);
- return run();
- connect_wifi(WIFI_SSID, WIFI_PASSWORD);
- connect_client(SCOPE_ID, DEVICE_ID, DEVICE_KEY);
- }
- void loop() {
- // put your main code here, to run repeatedly
- }
- void run(){
- for(cas; cas < 30;cas++){
- delay(1000);
- //unsigned long currentMillis = millis();
- //if(currentMillis - previousMillis > interval)
- //{
- //cas++;
- //previousMillis = currentMillis;
- Serial.println(cas);
- //}
- if(cas>20){
- digitalWrite(LED_PIN, HIGH);
- }
- }
- Serial.println("Tlacitko nezmacknuto.");
- }
- void resetcasovac(){
- cas = 0;
- digitalWrite(LED_PIN, LOW);
- Serial.println("Tlacitko zmacknuto.");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement