Page 2 of 3

Re: Pilne - kod ino

Posted: Mon Jun 24, 2019 9:15 pm
by lesny8
Deklarując zmienną rezerwujesz pamięć. Jeśli deklarujesz zmianną o takiej samej nazwie dwa razy to masz dwa adresy. Globalna zmienna żyje póki działa program, a lokalna umiera po zamknięciu funkcji, w której ciele był zadeklarowana. Kolejne wywołanie funkcji to kolejna deklaracja zmiennej, rezerwacja adresu itd.

Re: Pilne - kod ino

Posted: Mon Jun 24, 2019 9:16 pm
by QLQ
lesny8 wrote:
Mon Jun 24, 2019 9:08 pm
Ok, ale w void setup() masz zadeklarowaną zmienną o takiej samej nazwie i to do niej przypisujesz wartość, a nie do tej globalnej.
W void setup() daj po prostu

Code: Select all

rainrate = 914400.0 / tipcount;
zamiast

Code: Select all

double rainrate = 914400.0 / tipcount;
mam tak po zmianie i nie działa:

Code: Select all

                                              /**
   Supla.org NodeMCU WiFi minimal example
   Author: Programistyk - Kamil Kaminski <kamil@programistyk.pl>

   This example shows how to configure SuplaDevice for building for NodeMCU within Arduino IDE
*/

#include <srpc.h>
#include <log.h>
#include <eh.h>
#include <proto.h>
#include <IEEE754tools.h>
// We define our own ethernet layer
#define SUPLADEVICE_CPP
#include <SuplaDevice.h>
#include <lck.h>

#include <WiFiClient.h>
#include <ESP8266WiFiType.h>
#include <ESP8266WiFi.h>
#include <ESP8266WiFiScan.h>
#include <ESP8266WiFiMulti.h>
#include <WiFiServer.h>
#include <ESP8266WiFiGeneric.h>
#include <WiFiClientSecure.h>
#include <ESP8266WiFiAP.h>
#include <ESP8266WiFiSTA.h>
#include <WiFiUdp.h>
#include <Wire.h>
#include <OneWire.h>
#include <DallasTemperature.h>

#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_Sensor.h>
#define OLED_RESET 0
Adafruit_SSD1306 display(OLED_RESET); // GPIO5 - SCL , GPIO4 -SDA


const byte interruptPin = 12;
const int interval = 500;
volatile unsigned long tiptime = millis();
double rainrate;
unsigned long curtime;

#define NUMFLAKES 10
#define XPOS 0
#define YPOS 1
#define DELTAY 2


#define LOGO32_GLCD_HEIGHT 32
#define LOGO32_GLCD_WIDTH  32
static const unsigned char PROGMEM temp_glcd_bmp[] =
{ // temp_home
  0x00, 0x03, 0xc0, 0x00, 0x00, 0x04, 0x20, 0x00, 0x00, 0x08, 0x10, 0x00, 0x00, 0x08, 0x50, 0x00, 
  0x00, 0x08, 0x50, 0x00, 0x00, 0x08, 0x50, 0x00, 0x00, 0x08, 0x10, 0x00, 0x00, 0x09, 0x50, 0x00, 
  0x00, 0x08, 0xd0, 0x00, 0x00, 0x0b, 0x10, 0x00, 0x00, 0x0b, 0xd0, 0x00, 0x00, 0x0b, 0xd0, 0x00, 
  0x00, 0x0b, 0xd0, 0x00, 0x00, 0x0b, 0xd0, 0x00, 0x00, 0x0b, 0xd0, 0x00, 0x00, 0x0b, 0xd0, 0x00, 
  0x00, 0x0b, 0xd0, 0x00, 0x00, 0x0b, 0xd0, 0x00, 0x00, 0x0b, 0xd0, 0x00, 0x00, 0x0b, 0xd0, 0x00, 
  0x00, 0x0b, 0xd0, 0x00, 0x00, 0x0b, 0xd0, 0x00, 0x00, 0x0b, 0xd0, 0x00, 0x00, 0x17, 0xe8, 0x00, 
  0x00, 0x2f, 0xf4, 0x00, 0x00, 0x2f, 0x94, 0x00, 0x00, 0x2f, 0xb4, 0x00, 0x00, 0x2f, 0xf4, 0x00, 
  0x00, 0x07, 0xe0, 0x00, 0x00, 0x13, 0xc8, 0x00, 0x00, 0x08, 0x10, 0x00, 0x00, 0x03, 0xc0, 0x00
};

static const unsigned char PROGMEM waga_glcd_bmp[] =
{
 0x00,0x00,0x80,0x00, // ········▌·······
  0x00,0x01,0xC0,0x00, // ·······▐█·······
  0x00,0x01,0xC0,0x00, // ·······▐█·······
  0x00,0x01,0xC0,0x00, // ·······▐█·······
  0x3F,0xFF,0xFF,0xFC, // ·██████████████·
  0x3F,0xFF,0xFF,0xFE, // ·██████████████▌
  0x3F,0xFF,0xFF,0xFE, // ·██████████████▌
  0x07,0x81,0xC0,0xF0, // ··▐█▌··▐█···██··
  0x07,0x81,0x80,0xF0, // ··▐█▌··▐▌···██··
  0x0F,0xC1,0xC1,0xF8, // ··███··▐█··▐██▌·
  0x1C,0xC1,0xC1,0x98, // ·▐█·█··▐█··▐▌▐▌·
  0x18,0xE1,0xC3,0x8C, // ·▐▌·█▌·▐█··█▌·█·
  0x38,0x61,0xC3,0x0E, // ·█▌·▐▌·▐█··█··█▌
  0x30,0x71,0xC7,0x06, // ·█··▐█·▐█·▐█··▐▌
  0xFF,0xF9,0xCF,0xFF, // ██████▌▐█·██████
  0xFF,0xF9,0xCF,0xFF, // ██████▌▐█·██████
  0xFF,0xF9,0xCF,0xFF, // ██████▌▐█·██████
  0x7F,0xF9,0xCF,0xFF, // ▐█████▌▐█·██████
  0x3F,0xF1,0xC7,0xFE, // ·█████·▐█·▐████▌
  0x3F,0xE1,0xC3,0xFE, // ·████▌·▐█··████▌
  0x0F,0xC1,0xC1,0xF8, // ··███··▐█··▐██▌·
  0x00,0x01,0xC0,0x00, // ·······▐█·······
  0x00,0x01,0xC0,0x00, // ·······▐█·······
  0x00,0x01,0xC0,0x00, // ·······▐█·······
  0x00,0x01,0xC0,0x00, // ·······▐█·······
  0x00,0x01,0x80,0x00, // ·······▐▌·······
  0x00,0x1F,0xFC,0x00, // ·····▐█████·····
  0x00,0x3F,0xFE,0x00, // ·····██████▌····
  0x00,0x3F,0xFE,0x00, // ·····██████▌····
  0x00,0x3F,0xFE,0x00, // ·····██████▌····
  0x00,0x1F,0xFC,0x00, // ·····▐█████·····
  0x00,0x00,0x00,0x00  // ················
};


static const unsigned char PROGMEM logo32_glcd_bmp[] =
{
  // 'logo SUPLA'
  0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x03, 0xf8, 0x00, 0x00, 0x07, 0xfc, 0x00, 0x00,
  0x0e, 0x0e, 0x00, 0x00, 0x0c, 0x06, 0x00, 0x00, 0x1c, 0x03, 0x00, 0x00, 0x1c, 0x03, 0x00, 0x00,
  0x1c, 0x03, 0x00, 0x00, 0x0c, 0x07, 0x00, 0x00, 0x0e, 0x0f, 0x80, 0x00, 0x07, 0xfc, 0xe0, 0x00,
  0x03, 0xf8, 0x30, 0x00, 0x00, 0xf0, 0x0d, 0xe0, 0x00, 0x10, 0x07, 0x30, 0x00, 0x18, 0x02, 0x10,
  0x00, 0x18, 0x06, 0x18, 0x00, 0x08, 0x02, 0x10, 0x00, 0x08, 0x03, 0xf0, 0x00, 0x0c, 0x07, 0xc0,
  0x00, 0x04, 0x0c, 0x00, 0x00, 0x04, 0x08, 0x00, 0x00, 0x04, 0x10, 0x00, 0x00, 0x00, 0x20, 0x00,
  0x00, 0x03, 0xc0, 0x00, 0x00, 0x04, 0x40, 0x00, 0x00, 0x0c, 0x20, 0x00, 0x00, 0x0c, 0x20, 0x00,
  0x00, 0x04, 0x40, 0x00, 0x00, 0x03, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
static const unsigned char PROGMEM ASL_glcd_bmp[] =
{
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 
  0x00, 0x00, 0x60, 0x00, 0x00, 0x08, 0x21, 0x00, 0x00, 0x0c, 0x03, 0x00, 0x00, 0x00, 0x62, 0x00, 
  0x00, 0x1f, 0xf8, 0x00, 0x00, 0x3f, 0x0c, 0x00, 0x00, 0x61, 0x84, 0x00, 0x00, 0xc0, 0xc4, 0xe0, 
  0x01, 0xc0, 0xf4, 0x00, 0x03, 0x00, 0x1c, 0x00, 0x06, 0x00, 0x0c, 0x00, 0x06, 0x00, 0x0c, 0x00, 
  0x06, 0x10, 0xcd, 0x00, 0x03, 0x10, 0x99, 0x00, 0x01, 0x84, 0x30, 0x00, 0x00, 0x25, 0x00, 0x00, 
  0x00, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 
  };

char* Message[] = {"This is string 1",
                   "Already initialized",
                   "Cb not assigned",
                   "Invalid GUID",
                   "Unknown server address",
                   "Unknow location ID",
                   "Initialized",
                   "Channel limit exceeded",
                   "Rozlaczony",
                   "Rejstracja w toku",
                   "Iterate fail",
                   "Protocol version error",
                   "Bad credentials",
                   "Temporarily unawaliable",
                   "Location conflict",
                   "Channel conflict",
                   "Polaczony i gotowy",
                   "Device is diasbled",
                   "Location is disabled",
                   "Device limit execeeded"
                  };



#if (SSD1306_LCDHEIGHT != 64)
//#error("Height incorrect, please fix Adafruit_SSD1306.h!");
#endif

// ***** logowanie WiFi ********************************************************************************
WiFiClient client;

// Setup Supla connection
const char* ssid     = "xx";
const char* password = "xx";

char str[10];
char StatCommStr[25];
int StatCommInt;
byte Icon;
byte FiveSek;

//*****************************OPADY_DESZCZ*******************************************

double get_rain(int channelNumber, double t) {

    t=rainrate;
  
    
}
//**********************************WYLICZ OPADY****************************************
void count() {
  float de;
  // Grab the current ms count for common calculations
  unsigned long curtime = millis();
  
  // Make sure we don't record bounces
  if ((curtime - tiptime) < interval) {
    return;
  }
// How long since the last tip?
  unsigned long tipcount = curtime - tiptime;
  tiptime = curtime;
  
  // Calculate mm/hr from period between cup tips
  rainrate = 914400.0 / tipcount;
  
  Serial.print("Cup tip: ");
  Serial.print(tipcount);
  Serial.println("ms");  
  
  Serial.print("Opady deszczu: ");
  Serial.print(rainrate/10);
  Serial.println("l/m2");  
  Serial.println("mm/h");  

}
//**************************#########################################################
void timer0_ISR (void) {
  FiveSek++;
  if (FiveSek==2) {
    FiveSek=0;
    Icon++;
    if (Icon==3) Icon=1;
  }
  timer0_write(ESP.getCycleCount() + 80000000L); // 80MHz == 1sec 
}

//// ******* Funkcja główna *********************************************************************************
void setup() {
 
  Serial.begin(9600); 
 // Set up our digital pin as an interrupt
  pinMode(interruptPin, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(interruptPin), count, FALLING);
  
  noInterrupts();
  timer0_isr_init();
  timer0_attachInterrupt(timer0_ISR);
  timer0_write(ESP.getCycleCount() + 80000000L); // 80MHz == 1sec
  interrupts();
 
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);  // initialize with the I2C addr 0x3C (for the 128x64)
 
  Icon = 0;

  // Clear the buffer.
  display.clearDisplay();

  // text display tests
  display.setTextSize(3);
  display.setTextColor(WHITE);
  display.setRotation(2);
  display.setCursor(30, 25);
  display.print("SUPLA");
  drawbitmap(logo32_glcd_bmp, LOGO32_GLCD_HEIGHT, LOGO32_GLCD_WIDTH);
  display.display();





  // Replace the falowing GUID
char GUID[SUPLA_GUID_SIZE] = {0xF0,0xE2,0xA7,0x5A,0xF6,0xDF,0xE8,0x24,0xA6,0xAE,0x36,0x2A,0x8F,0x11,0xD7,0x18};

  //  GUID that you can retrieve from https://www.supla.org/arduino/get-guid

  // Ethernet MAC address
  uint8_t mac[6] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};

  /*
     Having your device already registered at cloud.supla.org,
     you want to change CHANNEL sequence or remove any of them,
     then you must also remove the device itself from cloud.supla.org.
     Otherwise you will get "Channel conflict!" error.
  */
    
          // CHANNEL0 
            SuplaDevice.addRainSensor(); //deszcz czujnik
    

 
  SuplaDevice.setName("R@F_Opady_Deszcz");
  SuplaDevice.setStatusFuncImpl(&status_func);

  SuplaDevice.begin(GUID,              // Global Unique Identifier
                    mac,               // Ethernet MAC address
                    "svr5.supla.org",  // SUPLA server address
                    111,                 // Location ID
                    "111");               // Location Password

}


// ***********************************************************************************************************
void loop() {
  SuplaDevice.iterate();
  DisplayTemp();

}

// ****   Obsługa OLED    ****************************************************************************************************

void DisplayTemp() {

  
 
  display.clearDisplay();
  display.setTextSize(3);
  display.setTextColor(WHITE);
  display.setRotation(2);
  display.setCursor(45, 25);  
 
  switch (Icon) {
      case 1:
        display.setTextSize(4);
        display.setCursor(30, 20 );  
     //   display.print(waga, 0);
        display.print("kg" );
        drawbitmap(waga_glcd_bmp, LOGO32_GLCD_HEIGHT, LOGO32_GLCD_WIDTH);
        
        break;
        
        case 2:
        display.setTextSize(4);
        display.setCursor(30, 20 );  
     //   display.print(waga, 0);
        display.print("kg" );
      
        drawbitmap(waga_glcd_bmp, LOGO32_GLCD_HEIGHT, LOGO32_GLCD_WIDTH);
        
        break;
     
    

//---------------------        
  };
  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.setCursor(0, 55);
  display.print(Message[StatCommInt - 1]);
  display.display();
  display.display();

}; //DisplayTemp

void drawbitmap(const uint8_t *bitmap, uint8_t w, uint8_t h) {
  uint8_t icons[NUMFLAKES][3];

  display.drawBitmap(0, 0, bitmap, w, h, WHITE);
} //drawbitmap


// Supla.org ethernet layer
int supla_arduino_tcp_read(void *buf, int count) {
  _supla_int_t size = client.available();

  if ( size > 0 ) {
    if ( size > count ) size = count;
    return client.read((uint8_t *)buf, size);
  };

  return -1;
};

int supla_arduino_tcp_write(void *buf, int count) {
  return client.write((const uint8_t *)buf, count);
};

bool supla_arduino_svr_connect(const char *server, int port) {
  return client.connect(server, 2015);
}

bool supla_arduino_svr_connected(void) {
  return client.connected();
}

void supla_arduino_svr_disconnect(void) {
  client.stop();
}

void supla_arduino_eth_setup(uint8_t mac[6], IPAddress *ip) {

  // Serial.println("WiFi init");
  WiFi.begin(ssid, password);

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

 // Serial.print("\nlocalIP: ");
 // Serial.println(WiFi.localIP());
  //Serial.print("subnetMask: ");
 // Serial.println(WiFi.subnetMask());
  //Serial.print("gatewayIP: ");
  //Serial.println(WiFi.gatewayIP());
}

SuplaDeviceCallbacks supla_arduino_get_callbacks(void) {
  SuplaDeviceCallbacks cb;

  cb.tcp_read = &supla_arduino_tcp_read;
  cb.tcp_write = &supla_arduino_tcp_write;
  cb.eth_setup = &supla_arduino_eth_setup;
  cb.svr_connected = &supla_arduino_svr_connected;
  cb.svr_connect = &supla_arduino_svr_connect;
  cb.svr_disconnect = &supla_arduino_svr_disconnect;
  cb.get_rain = get_rain;
  cb.get_temperature_and_humidity = NULL;
  cb.get_pressure = NULL; 
  cb.get_temperature = NULL;
  cb.get_rgbw_value = NULL;
  cb.set_rgbw_value = NULL;
  cb.get_distance= NULL;

  return cb;
}



void status_func(int status, const char *msg) {
  Serial.print("Status : ");
  Serial.print(status);
  StatCommInt = status;
  Serial.print(" - ");
  Serial.println(Message[StatCommInt - 1]);
  display.fillRect(0, 55, 128, 65, BLACK);

  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.setRotation(2);
  display.setCursor(0, 55);
  display.print(Message[StatCommInt - 1]);
  display.display();

}

Re: Pilne - kod ino

Posted: Mon Jun 24, 2019 9:26 pm
by QLQ
JEEEEEEEEEEE DZIAŁA !!!!!!!!!!!!!! :lol: :lol: :lol: :lol: :lol:


EDIT : AŻ SIĘ MUSZĘ NAPIĆ

Re: Pilne - kod ino

Posted: Mon Jun 24, 2019 9:28 pm
by Zybi
Poprawiłem funkcję SuplaDeviceCallbacks supla_arduino_get_callbacks(void) - brakowało "&" przy get_rain:

Code: Select all

SuplaDeviceCallbacks supla_arduino_get_callbacks(void) {
  SuplaDeviceCallbacks cb;

  cb.tcp_read = &supla_arduino_tcp_read;
  cb.tcp_write = &supla_arduino_tcp_write;
  cb.eth_setup = &supla_arduino_eth_setup;
  cb.svr_connected = &supla_arduino_svr_connected;
  cb.svr_connect = &supla_arduino_svr_connect;
  cb.svr_disconnect = &supla_arduino_svr_disconnect;
  cb.get_rain = &get_rain;
  cb.get_temperature_and_humidity = NULL;
  cb.get_pressure = NULL; 
  cb.get_temperature = NULL;
  cb.get_rgbw_value = NULL;
  cb.set_rgbw_value = NULL;
  cb.get_distance= NULL;

  return cb;
}

Re: Pilne - kod ino

Posted: Mon Jun 24, 2019 9:29 pm
by QLQ
Zybi wrote:
Mon Jun 24, 2019 9:28 pm
Poprawiłem funkcję SuplaDeviceCallbacks supla_arduino_get_callbacks(void) - brakowało "&" przy get_rain:

Code: Select all

SuplaDeviceCallbacks supla_arduino_get_callbacks(void) {
  SuplaDeviceCallbacks cb;

  cb.tcp_read = &supla_arduino_tcp_read;
  cb.tcp_write = &supla_arduino_tcp_write;
  cb.eth_setup = &supla_arduino_eth_setup;
  cb.svr_connected = &supla_arduino_svr_connected;
  cb.svr_connect = &supla_arduino_svr_connect;
  cb.svr_disconnect = &supla_arduino_svr_disconnect;
  cb.get_rain = &get_rain;
  cb.get_temperature_and_humidity = NULL;
  cb.get_pressure = NULL; 
  cb.get_temperature = NULL;
  cb.get_rgbw_value = NULL;
  cb.set_rgbw_value = NULL;
  cb.get_distance= NULL;

  return cb;
}
bez tego też w Cloud był widziany ale nie przesyłało wartości ale zaraz sprawdzę

Re: Pilne - kod ino

Posted: Mon Jun 24, 2019 9:30 pm
by lesny8
get_rain nic nie zwraca
dodaj jeszcze

Code: Select all

return t; 

Re: Pilne - kod ino

Posted: Mon Jun 24, 2019 9:57 pm
by QLQ
lesny8 wrote:
Mon Jun 24, 2019 9:30 pm
get_rain nic nie zwraca
dodaj jeszcze

Code: Select all

return t; 
DZIAŁA PANIE DZIAŁA
Już się porno konwertuje do wrzucenia na YT :)

Re: Pilne - kod ino

Posted: Mon Jun 24, 2019 10:02 pm
by lesny8
QLQ wrote:
Mon Jun 24, 2019 9:57 pm
DZIAŁA PANIE DZIAŁA
Już się porno konwertuje do wrzucenia na YT :)
:lol:

Re: Pilne - kod ino

Posted: Mon Jun 24, 2019 10:02 pm
by QLQ
SERDECZNIE DZIĘKUJĘ ZA POMOC I ZAINTERESOWANIE
kod poniżej:

Code: Select all

                                              /**
                                              /**
   Supla.org NodeMCU WiFi minimal example
   Author: Programistyk - Kamil Kaminski <kamil@programistyk.pl>

   This example shows how to configure SuplaDevice for building for NodeMCU within Arduino IDE
*/

#include <srpc.h>
#include <log.h>
#include <eh.h>
#include <proto.h>
#include <IEEE754tools.h>
// We define our own ethernet layer
#define SUPLADEVICE_CPP
#include <SuplaDevice.h>
#include <lck.h>

#include <WiFiClient.h>
#include <ESP8266WiFiType.h>
#include <ESP8266WiFi.h>
#include <ESP8266WiFiScan.h>
#include <ESP8266WiFiMulti.h>
#include <WiFiServer.h>
#include <ESP8266WiFiGeneric.h>
#include <WiFiClientSecure.h>
#include <ESP8266WiFiAP.h>
#include <ESP8266WiFiSTA.h>
#include <WiFiUdp.h>
#include <Wire.h>
#include <OneWire.h>
#include <DallasTemperature.h>

#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_Sensor.h>
#define OLED_RESET 0
Adafruit_SSD1306 display(OLED_RESET); // GPIO5 - SCL , GPIO4 -SDA


const byte interruptPin = 12;
const int interval = 500;
volatile unsigned long tiptime = millis();
double rainrate;
unsigned long curtime;

#define NUMFLAKES 10
#define XPOS 0
#define YPOS 1
#define DELTAY 2


#define LOGO32_GLCD_HEIGHT 32
#define LOGO32_GLCD_WIDTH  32
static const unsigned char PROGMEM temp_glcd_bmp[] =
{ // temp_home
  0x00, 0x03, 0xc0, 0x00, 0x00, 0x04, 0x20, 0x00, 0x00, 0x08, 0x10, 0x00, 0x00, 0x08, 0x50, 0x00, 
  0x00, 0x08, 0x50, 0x00, 0x00, 0x08, 0x50, 0x00, 0x00, 0x08, 0x10, 0x00, 0x00, 0x09, 0x50, 0x00, 
  0x00, 0x08, 0xd0, 0x00, 0x00, 0x0b, 0x10, 0x00, 0x00, 0x0b, 0xd0, 0x00, 0x00, 0x0b, 0xd0, 0x00, 
  0x00, 0x0b, 0xd0, 0x00, 0x00, 0x0b, 0xd0, 0x00, 0x00, 0x0b, 0xd0, 0x00, 0x00, 0x0b, 0xd0, 0x00, 
  0x00, 0x0b, 0xd0, 0x00, 0x00, 0x0b, 0xd0, 0x00, 0x00, 0x0b, 0xd0, 0x00, 0x00, 0x0b, 0xd0, 0x00, 
  0x00, 0x0b, 0xd0, 0x00, 0x00, 0x0b, 0xd0, 0x00, 0x00, 0x0b, 0xd0, 0x00, 0x00, 0x17, 0xe8, 0x00, 
  0x00, 0x2f, 0xf4, 0x00, 0x00, 0x2f, 0x94, 0x00, 0x00, 0x2f, 0xb4, 0x00, 0x00, 0x2f, 0xf4, 0x00, 
  0x00, 0x07, 0xe0, 0x00, 0x00, 0x13, 0xc8, 0x00, 0x00, 0x08, 0x10, 0x00, 0x00, 0x03, 0xc0, 0x00
};

static const unsigned char PROGMEM waga_glcd_bmp[] =
{
 0x00,0x00,0x80,0x00, // ········▌·······
  0x00,0x01,0xC0,0x00, // ·······▐█·······
  0x00,0x01,0xC0,0x00, // ·······▐█·······
  0x00,0x01,0xC0,0x00, // ·······▐█·······
  0x3F,0xFF,0xFF,0xFC, // ·██████████████·
  0x3F,0xFF,0xFF,0xFE, // ·██████████████▌
  0x3F,0xFF,0xFF,0xFE, // ·██████████████▌
  0x07,0x81,0xC0,0xF0, // ··▐█▌··▐█···██··
  0x07,0x81,0x80,0xF0, // ··▐█▌··▐▌···██··
  0x0F,0xC1,0xC1,0xF8, // ··███··▐█··▐██▌·
  0x1C,0xC1,0xC1,0x98, // ·▐█·█··▐█··▐▌▐▌·
  0x18,0xE1,0xC3,0x8C, // ·▐▌·█▌·▐█··█▌·█·
  0x38,0x61,0xC3,0x0E, // ·█▌·▐▌·▐█··█··█▌
  0x30,0x71,0xC7,0x06, // ·█··▐█·▐█·▐█··▐▌
  0xFF,0xF9,0xCF,0xFF, // ██████▌▐█·██████
  0xFF,0xF9,0xCF,0xFF, // ██████▌▐█·██████
  0xFF,0xF9,0xCF,0xFF, // ██████▌▐█·██████
  0x7F,0xF9,0xCF,0xFF, // ▐█████▌▐█·██████
  0x3F,0xF1,0xC7,0xFE, // ·█████·▐█·▐████▌
  0x3F,0xE1,0xC3,0xFE, // ·████▌·▐█··████▌
  0x0F,0xC1,0xC1,0xF8, // ··███··▐█··▐██▌·
  0x00,0x01,0xC0,0x00, // ·······▐█·······
  0x00,0x01,0xC0,0x00, // ·······▐█·······
  0x00,0x01,0xC0,0x00, // ·······▐█·······
  0x00,0x01,0xC0,0x00, // ·······▐█·······
  0x00,0x01,0x80,0x00, // ·······▐▌·······
  0x00,0x1F,0xFC,0x00, // ·····▐█████·····
  0x00,0x3F,0xFE,0x00, // ·····██████▌····
  0x00,0x3F,0xFE,0x00, // ·····██████▌····
  0x00,0x3F,0xFE,0x00, // ·····██████▌····
  0x00,0x1F,0xFC,0x00, // ·····▐█████·····
  0x00,0x00,0x00,0x00  // ················
};


static const unsigned char PROGMEM logo32_glcd_bmp[] =
{
  // 'logo SUPLA'
  0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x03, 0xf8, 0x00, 0x00, 0x07, 0xfc, 0x00, 0x00,
  0x0e, 0x0e, 0x00, 0x00, 0x0c, 0x06, 0x00, 0x00, 0x1c, 0x03, 0x00, 0x00, 0x1c, 0x03, 0x00, 0x00,
  0x1c, 0x03, 0x00, 0x00, 0x0c, 0x07, 0x00, 0x00, 0x0e, 0x0f, 0x80, 0x00, 0x07, 0xfc, 0xe0, 0x00,
  0x03, 0xf8, 0x30, 0x00, 0x00, 0xf0, 0x0d, 0xe0, 0x00, 0x10, 0x07, 0x30, 0x00, 0x18, 0x02, 0x10,
  0x00, 0x18, 0x06, 0x18, 0x00, 0x08, 0x02, 0x10, 0x00, 0x08, 0x03, 0xf0, 0x00, 0x0c, 0x07, 0xc0,
  0x00, 0x04, 0x0c, 0x00, 0x00, 0x04, 0x08, 0x00, 0x00, 0x04, 0x10, 0x00, 0x00, 0x00, 0x20, 0x00,
  0x00, 0x03, 0xc0, 0x00, 0x00, 0x04, 0x40, 0x00, 0x00, 0x0c, 0x20, 0x00, 0x00, 0x0c, 0x20, 0x00,
  0x00, 0x04, 0x40, 0x00, 0x00, 0x03, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
static const unsigned char PROGMEM ASL_glcd_bmp[] =
{
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 
  0x00, 0x00, 0x60, 0x00, 0x00, 0x08, 0x21, 0x00, 0x00, 0x0c, 0x03, 0x00, 0x00, 0x00, 0x62, 0x00, 
  0x00, 0x1f, 0xf8, 0x00, 0x00, 0x3f, 0x0c, 0x00, 0x00, 0x61, 0x84, 0x00, 0x00, 0xc0, 0xc4, 0xe0, 
  0x01, 0xc0, 0xf4, 0x00, 0x03, 0x00, 0x1c, 0x00, 0x06, 0x00, 0x0c, 0x00, 0x06, 0x00, 0x0c, 0x00, 
  0x06, 0x10, 0xcd, 0x00, 0x03, 0x10, 0x99, 0x00, 0x01, 0x84, 0x30, 0x00, 0x00, 0x25, 0x00, 0x00, 
  0x00, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 
  };

char* Message[] = {"This is string 1",
                   "Already initialized",
                   "Cb not assigned",
                   "Invalid GUID",
                   "Unknown server address",
                   "Unknow location ID",
                   "Initialized",
                   "Channel limit exceeded",
                   "Rozlaczony",
                   "Rejstracja w toku",
                   "Iterate fail",
                   "Protocol version error",
                   "Bad credentials",
                   "Temporarily unawaliable",
                   "Location conflict",
                   "Channel conflict",
                   "Polaczony i gotowy",
                   "Device is diasbled",
                   "Location is disabled",
                   "Device limit execeeded"
                  };



#if (SSD1306_LCDHEIGHT != 64)
//#error("Height incorrect, please fix Adafruit_SSD1306.h!");
#endif

// ***** logowanie WiFi ********************************************************************************
WiFiClient client;

// Setup Supla connection
const char* ssid     = "Rxx";
const char* password = "xxx79";

char str[10];
char StatCommStr[25];
int StatCommInt;
byte Icon;
byte FiveSek;

//*****************************OPADY_DESZCZ*******************************************

double get_rain(int channelNumber, double t) {


//double t = -275;  
    t = rainrate*100;
    return t;
  
  
    
}
//**********************************WYLICZ OPADY****************************************
void count() {
  float de;
  // Grab the current ms count for common calculations
  unsigned long curtime = millis();
  
  // Make sure we don't record bounces
  if ((curtime - tiptime) < interval) {
    return;
  }
// How long since the last tip?
  unsigned long tipcount = curtime - tiptime;
  tiptime = curtime;
  
  // Calculate mm/hr from period between cup tips
  rainrate = 914400.0 / tipcount;
  
  Serial.print("Cup tip: ");
  Serial.print(tipcount);
  Serial.println("ms");  
  
  Serial.print("Opady deszczu: ");
  Serial.print(rainrate/10);
  Serial.println("l/m2");  
  Serial.println("mm/h");  

}
//**************************#########################################################
void timer0_ISR (void) {
  FiveSek++;
  if (FiveSek==2) {
    FiveSek=0;
    Icon++;
    if (Icon==3) Icon=1;
  }
  timer0_write(ESP.getCycleCount() + 80000000L); // 80MHz == 1sec 
}

//// ******* Funkcja główna *********************************************************************************
void setup() {
 
  Serial.begin(9600); 
 // Set up our digital pin as an interrupt
  pinMode(interruptPin, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(interruptPin), count, FALLING);
  
  noInterrupts();
  timer0_isr_init();
  timer0_attachInterrupt(timer0_ISR);
  timer0_write(ESP.getCycleCount() + 80000000L); // 80MHz == 1sec
  interrupts();
 
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);  // initialize with the I2C addr 0x3C (for the 128x64)
 
  Icon = 0;

  // Clear the buffer.
  display.clearDisplay();

  // text display tests
  display.setTextSize(3);
  display.setTextColor(WHITE);
  display.setRotation(2);
  display.setCursor(30, 25);
  display.print("SUPLA");
  drawbitmap(logo32_glcd_bmp, LOGO32_GLCD_HEIGHT, LOGO32_GLCD_WIDTH);
  display.display();





  // Replace the falowing GUID
char GUID[SUPLA_GUID_SIZE] = {0x57,0x33,0x4D,0xDC,0x1B,0x1D,0x80,0xD9,0x06,0xD9,0x63,0xF4,0x5A,0xC0,0x05,0x3F};

  //  GUID that you can retrieve from https://www.supla.org/arduino/get-guid

  // Ethernet MAC address
  uint8_t mac[6] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};

  /*
     Having your device already registered at cloud.supla.org,
     you want to change CHANNEL sequence or remove any of them,
     then you must also remove the device itself from cloud.supla.org.
     Otherwise you will get "Channel conflict!" error.
  */
    
          // CHANNEL0 
            SuplaDevice.addRainSensor(); //deszcz czujnik
    

 
  SuplaDevice.setName("R@F_Deszcz");
  SuplaDevice.setStatusFuncImpl(&status_func);

  SuplaDevice.begin(GUID,              // Global Unique Identifier
                    mac,               // Ethernet MAC address
                    "svr5.supla.org",  // SUPLA server address
                    111,                 // Location ID
                    "1111");               // Location Password

}


// ***********************************************************************************************************
void loop() {
  SuplaDevice.iterate();
  DisplayTemp();

}

// ****   Obsługa OLED    ****************************************************************************************************

void DisplayTemp() {

  
 
  display.clearDisplay();
  display.setTextSize(3);
  display.setTextColor(WHITE);
  display.setRotation(2);
  display.setCursor(45, 25);  
 
  switch (Icon) {
      case 1:
        display.setTextSize(4);
        display.setCursor(30, 20 );  
     //   display.print(waga, 0);
        display.print("kg" );
        drawbitmap(waga_glcd_bmp, LOGO32_GLCD_HEIGHT, LOGO32_GLCD_WIDTH);
        
        break;
        
        case 2:
        display.setTextSize(4);
        display.setCursor(30, 20 );  
     //   display.print(waga, 0);
        display.print("kg" );
      
        drawbitmap(waga_glcd_bmp, LOGO32_GLCD_HEIGHT, LOGO32_GLCD_WIDTH);
        
        break;
     
    

//---------------------        
  };
  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.setCursor(0, 55);
  display.print(Message[StatCommInt - 1]);
  display.display();
  display.display();

}; //DisplayTemp

void drawbitmap(const uint8_t *bitmap, uint8_t w, uint8_t h) {
  uint8_t icons[NUMFLAKES][3];

  display.drawBitmap(0, 0, bitmap, w, h, WHITE);
} //drawbitmap


// Supla.org ethernet layer
int supla_arduino_tcp_read(void *buf, int count) {
  _supla_int_t size = client.available();

  if ( size > 0 ) {
    if ( size > count ) size = count;
    return client.read((uint8_t *)buf, size);
  };

  return -1;
};

int supla_arduino_tcp_write(void *buf, int count) {
  return client.write((const uint8_t *)buf, count);
};

bool supla_arduino_svr_connect(const char *server, int port) {
  return client.connect(server, 2015);
}

bool supla_arduino_svr_connected(void) {
  return client.connected();
}

void supla_arduino_svr_disconnect(void) {
  client.stop();
}

void supla_arduino_eth_setup(uint8_t mac[6], IPAddress *ip) {

  // Serial.println("WiFi init");
  WiFi.begin(ssid, password);

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

 // Serial.print("\nlocalIP: ");
 // Serial.println(WiFi.localIP());
  //Serial.print("subnetMask: ");
 // Serial.println(WiFi.subnetMask());
  //Serial.print("gatewayIP: ");
  //Serial.println(WiFi.gatewayIP());
}

SuplaDeviceCallbacks supla_arduino_get_callbacks(void) {
  SuplaDeviceCallbacks cb;

  cb.tcp_read = &supla_arduino_tcp_read;
  cb.tcp_write = &supla_arduino_tcp_write;
  cb.eth_setup = &supla_arduino_eth_setup;
  cb.svr_connected = &supla_arduino_svr_connected;
  cb.svr_connect = &supla_arduino_svr_connect;
  cb.svr_disconnect = &supla_arduino_svr_disconnect;
  cb.get_rain = get_rain;
  cb.get_temperature_and_humidity = NULL;
  cb.get_pressure = NULL; 
  cb.get_temperature = NULL;
  cb.get_rgbw_value = NULL;
  cb.set_rgbw_value = NULL;
  cb.get_distance= NULL;

  return cb;
}



void status_func(int status, const char *msg) {
  Serial.print("Status : ");
  Serial.print(status);
  StatCommInt = status;
  Serial.print(" - ");
  Serial.println(Message[StatCommInt - 1]);
  display.fillRect(0, 55, 128, 65, BLACK);

  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.setRotation(2);
  display.setCursor(0, 55);
  display.print(Message[StatCommInt - 1]);
  display.display();

}




Re: Pilne - kod ino

Posted: Mon Jun 24, 2019 10:07 pm
by QLQ
lesny8 wrote:
Mon Jun 24, 2019 10:02 pm
QLQ wrote:
Mon Jun 24, 2019 9:57 pm
DZIAŁA PANIE DZIAŁA
Już się porno konwertuje do wrzucenia na YT :)
:lol:
Się wrzuca - jeszcze parę minut:
https://youtu.be/Jp13kC01chg


EDIT 00:14 - jeszcze 4 min