• Witaj na Forum Arduino Polska! Zapraszamy do rejestracji!
  • Znajdziesz tutaj wiele informacji na temat hardware / software.
Witaj! Logowanie Rejestracja


Ocena wątku:
  • 0 głosów - średnia: 0
  • 1
  • 2
  • 3
  • 4
  • 5
remoteme i pobranie zmiennych
#1
Witam, chciałem przerobić swoje Arduino sterujące oświetleniem w akwarium aby było sterowane przez www, chciałem do tego wykorzystać platformę remoteme.org.
Gdzie wpisuję godzinę zapalenia światła oraz natężenie.

Ale nie umiem pobrać tych zmiennych i np wyświetlić w konsoli lub pobrać wartość aby na jej podstawie określić godzinę ścienienia światła.
Czy ktoś korzystał z tej platformy i może mi podpowiedzieć co mam dalej zrobić.



Kod:
#define WIFI_NAME "111"
#define WIFI_PASSWORD "111"
#define DEVICE_ID 2
#define DEVICE_NAME "111"
#define TOKEN "11111"


#include <RemoteMe.h>
#include <RemoteMeWebSocketConnector.h> //!important library needs WebSockets by Markus Sattler Please install it from Library manager
#include <ESP8266WiFi.h>
#include <Wire.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <NTPClient.h>
#include <WiFiUdp.h>


int ledPinRoyalBlue = 1;
int ledPinBlue = 2;
int ledPinWhite = 3;
int ledPinRoyalBlue5V = 4;


RemoteMe& remoteMe = RemoteMe::getInstance(TOKEN, DEVICE_ID);

// Define NTP Client to get time
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP);

// Variables to save date and time
String formattedDate;
String dayStamp;
String timeStamp;

//Variable to set
int HOUR = 60 * 60;
int MINUTE = 60;
int TARGET_BRIGHTNESS = 255; //(255 * 4) / 3;  // Target brightness is 3/4 of full



//*************** CODE FOR CONFORTABLE VARIABLE SET *********************

inline void setAkwarium(int32_t i) {remoteMe.getVariables()->setInteger("Akwarium", i); }
inline void setBlue(int32_t i) {remoteMe.getVariables()->setInteger("Blue", i); }
inline void setBurza(boolean b) {remoteMe.getVariables()->setBoolean("Burza", b); }
inline void setElektryka(int32_t i) {remoteMe.getVariables()->setInteger("Elektryka", i); }
inline void setGrza_ka(boolean b) {remoteMe.getVariables()->setBoolean("Grza?ka", b); }
inline void setKarmienie(boolean b) {remoteMe.getVariables()->setBoolean("Karmienie", b); }
inline void setLedOFF_H(int32_t i) {remoteMe.getVariables()->setInteger("LedOFF-H", i); }
inline void setLedOFF_M(int32_t i) {remoteMe.getVariables()->setInteger("LedOFF-M", i); }
inline void setLedON_H(int32_t i) {remoteMe.getVariables()->setInteger("LedON-H", i); }
inline void setLedON_M(int32_t i) {remoteMe.getVariables()->setInteger("LedON-M", i); }
inline void setNocne(boolean b) {remoteMe.getVariables()->setBoolean("Nocne", b); }
inline void setNocne_LedOFF_H(int32_t i) {remoteMe.getVariables()->setInteger("Nocne-LedOFF-H", i); }
inline void setNocne_LedOFF_M(int32_t i) {remoteMe.getVariables()->setInteger("Nocne-LedOFF-M", i); }
inline void setNocne_LedON_H(int32_t i) {remoteMe.getVariables()->setInteger("Nocne-LedON-H", i); }
inline void setNocne_LedON_M(int32_t i) {remoteMe.getVariables()->setInteger("Nocne-LedON-M", i); }
inline void setOdpieniacz(boolean b) {remoteMe.getVariables()->setBoolean("Odpieniacz", b); }
inline void setPompa(boolean b) {remoteMe.getVariables()->setBoolean("Pompa", b); }
inline void setRoyalBlue(int32_t i) {remoteMe.getVariables()->setInteger("RoyalBlue", i); }
inline void setRoyalBlue5V(int32_t i) {remoteMe.getVariables()->setInteger("RoyalBlue5V", i); }
inline void setSump(int32_t i) {remoteMe.getVariables()->setInteger("Sump", i); }
inline void setWhite(int32_t i) {remoteMe.getVariables()->setInteger("White", i); }

//*************** IMPLEMENT FUNCTIONS BELOW *********************


void onAkwariumChange(int32_t i) {
    Serial.printf("onAkwariumChange: i: %d\n",i);
}

void onBlueChange(int32_t i) {
    Serial.printf("onBlueChange: i: %d\n",i);
}

void onBurzaChange(boolean b) {
    Serial.printf("onBurzaChange: b: %d\n",b);
}

void onElektrykaChange(int32_t i) {
    Serial.printf("onElektrykaChange: i: %d\n",i);
}

void onGrza_kaChange(boolean b) {
    Serial.printf("onGrza_kaChange: b: %d\n",b);
}

void onKarmienieChange(boolean b) {
    Serial.printf("onKarmienieChange: b: %d\n",b);
}

void onLedOFF_HChange(int32_t i) {
    Serial.printf("onLedOFF_HChange: i: %d\n",i);
}

void onLedOFF_MChange(int32_t i) {
    Serial.printf("onLedOFF_MChange: i: %d\n",i);
}

void onLedON_HChange(int32_t i) {
    Serial.printf("onLedON_HChange: i: %d\n",i);
}

void onLedON_MChange(int32_t i) {
    Serial.printf("onLedON_MChange: i: %d\n",i);
    
}

void onNocneChange(boolean b) {
    Serial.printf("onNocneChange: b: %d\n",b);
}

void onNocne_LedOFF_HChange(int32_t i) {
    Serial.printf("onNocne_LedOFF_HChange: i: %d\n",i);
}

void onNocne_LedOFF_MChange(int32_t i) {
    Serial.printf("onNocne_LedOFF_MChange: i: %d\n",i);
}

void onNocne_LedON_HChange(int32_t i) {
    Serial.printf("onNocne_LedON_HChange: i: %d\n",i);
}

void onNocne_LedON_MChange(int32_t i) {
    Serial.printf("onNocne_LedON_MChange: i: %d\n",i);
}

void onOdpieniaczChange(boolean b) {
    Serial.printf("onOdpieniaczChange: b: %d\n",b);
    
}

void onPompaChange(boolean b) {
    Serial.printf("onPompaChange: b: %d\n",b);
}

void onRoyalBlueChange(int32_t i) {
    Serial.printf("onRoyalBlueChange: i: %d\n",i);
}

void onRoyalBlue5VChange(int32_t i) {
    Serial.printf("onRoyalBlue5VChange: i: %d\n",i);
}

void onSumpChange(int32_t i) {
    Serial.printf("onSumpChange: i: %d\n",i);
}

void onWhiteChange(int32_t i) {
    Serial.printf("onWhiteChange: i: %d\n",i);
  
}




void setup() {
  
    Serial.begin(115200);
    while (!Serial) ; // wait for serial
    WiFi.begin(WIFI_NAME, WIFI_PASSWORD);
    Serial.println(WIFI_NAME);
    
    while (WiFi.status() != WL_CONNECTED) {
        delay(100);
    }


  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }

  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());   //You can get IP address assigned to ESP

    remoteMe.getVariables()->observeInteger("Akwarium" ,onAkwariumChange);
    remoteMe.getVariables()->observeInteger("Blue" ,onBlueChange);
    remoteMe.getVariables()->observeBoolean("Burza" ,onBurzaChange);
    remoteMe.getVariables()->observeInteger("Elektryka" ,onElektrykaChange);
    remoteMe.getVariables()->observeBoolean("Grza?ka" ,onGrza_kaChange);
    remoteMe.getVariables()->observeBoolean("Karmienie" ,onKarmienieChange);
    remoteMe.getVariables()->observeInteger("LedOFF-H" ,onLedOFF_HChange);
    remoteMe.getVariables()->observeInteger("LedOFF-M" ,onLedOFF_MChange);
    remoteMe.getVariables()->observeInteger("LedON-H" ,onLedON_HChange);
    remoteMe.getVariables()->observeInteger("LedON-M" ,onLedON_MChange);
    remoteMe.getVariables()->observeBoolean("Nocne" ,onNocneChange);
    remoteMe.getVariables()->observeInteger("Nocne-LedOFF-H" ,onNocne_LedOFF_HChange);
    remoteMe.getVariables()->observeInteger("Nocne-LedOFF-M" ,onNocne_LedOFF_MChange);
    remoteMe.getVariables()->observeInteger("Nocne-LedON-H" ,onNocne_LedON_HChange);
    remoteMe.getVariables()->observeInteger("Nocne-LedON-M" ,onNocne_LedON_MChange);
    remoteMe.getVariables()->observeBoolean("Odpieniacz" ,onOdpieniaczChange);
    remoteMe.getVariables()->observeBoolean("Pompa" ,onPompaChange);
    remoteMe.getVariables()->observeInteger("RoyalBlue" ,onRoyalBlueChange);
    remoteMe.getVariables()->observeInteger("RoyalBlue5V" ,onRoyalBlue5VChange);
    remoteMe.getVariables()->observeInteger("Sump" ,onSumpChange);
    remoteMe.getVariables()->observeInteger("White" ,onWhiteChange);

    remoteMe.setConnector(new RemoteMeWebSocketConnector());

    remoteMe.sendRegisterDeviceMessage(DEVICE_NAME);


    // Initialize a NTPClient to get time
  timeClient.begin();
  // Set offset time in seconds to adjust for your timezone, for example:
  // GMT +1 = 3600
  // GMT +8 = 28800
  // GMT -1 = -3600
  // GMT 0 = 0
  timeClient.setTimeOffset(7200);
  
// testy ustawiania zmiwnnych
  //  setNocne_LedOFF_HD (00);
}


void loop() {


    while(!timeClient.update()) {
    timeClient.forceUpdate();
  }
  // The formattedDate comes with the following format:
  // 2018-05-28T16:00:13Z
  // We need to extract date and time
  formattedDate = timeClient.getFormattedDate();
  //Serial.println(formattedDate);

  // Extract date
  int splitT = formattedDate.indexOf("T");
  dayStamp = formattedDate.substring(0, splitT);
// Serial.print("DATE: ");
  //Serial.println(dayStamp);
  // Extract time
  timeStamp = formattedDate.substring(splitT+1, formattedDate.length()-1);
// Serial.print("HOUR: ");
  //Serial.println(timeStamp);
  delay(1000);
//int HH = void onLedON_MChange(int32_t i)

remoteMe.loop();
int time = timeClient.getHours() * HOUR + timeClient.getMinutes() * MINUTE + timeClient.getSeconds();

Serial.println(time);
  //Serial.print(timeClient.getHours());
// Serial.print(timeClient.getMinutes());
// Serial.println(timeClient.getSeconds());
int White ;
Serial.println(White);

    Serial.printf("onPompaChange: b: %d\n");


//analogWrite(ledPinRoyalBlue,  brightness(time, (LedON-H * HOUR) + (onLedON_MChange * MINUTE), (onLedOFF_HChange * HOUR) + (onLedOFF_MChange * MINUTE)));
//analogWrite(ledPinBlue,  brightness(time, HH*HOUR+onLedON_MChange*MINUTE, onLedOFF_HChange*HOUR+onLedOFF_MChange*MINUTE));
//analogWrite(ledPinWhite,  brightness(time, HH*HOUR+onLedON_MChange*MINUTE, onLedOFF_HChange*HOUR+onLedOFF_MChange*MINUTE));
//analogWrite(ledPinRoyalBlue5V,  brightness(time, onLedON_HChange*HOUR+onLedON_MChange*MINUTE, onLedOFF_HChange*HOUR+onLedOFF_MChange*MINUTE));

}

byte brightness(int time, int fadeUpStart, int fadeDownStart)
{
    //  Mid day, light is at maximum brightness
    if (time >= fadeUpStart + 2*HOUR  && time <= fadeDownStart)
        return TARGET_BRIGHTNESS;

   // Dawn:  fade up the light
    if (time >= fadeUpStart && time <= fadeUpStart + 2*HOUR)  // Fading up
           {
           int seconds = time - fadeUpStart;  // Number of seconds into the fade time
           return TARGET_BRIGHTNESS * seconds / (HOUR*2);  // Fade up based on portion of interval completed.
           }

   // Evening: Fade down the light
   if (time >= fadeDownStart && time <= fadeDownStart + 2*HOUR)  // Fading down
           {
           int seconds = (fadeDownStart + (HOUR*2)) - time;  // Number of seconds remaining in the fade time
           return TARGET_BRIGHTNESS * seconds / (HOUR*2);  // Fade down based on portion of interval left.
           }

    // The remaining times are night and the lights is off
    return 0;  // Shouldn't get here
    }
 
Odpowiedź
  


Skocz do:


Przeglądający: 1 gości