marți, 10 decembrie 2019

main esp2866

//Include the needed library, we will use softer serial communication with the ESP8266
#include
#include

//LCD config
#include
#include
LiquidCrystal_I2C lcd(0x27,20,4);  //sometimes the LCD adress is not 0x3f. Change to 0x27 if it dosn't work.


//Define the used
#define ESP8266_RX 10  //Connect the TX pin from the ESP to this RX pin of the Arduino
#define ESP8266_TX 11  //Connect the TX pin from the Arduino to the RX pin of ESP

int LED1 = 2;
int LED2 = 3;
int LED3 = 4;
int LED4 = 5;
int LED5 = 6;
int Potentiometer_1 = A0;
int Potentiometer_2 = A1;
int Potentiometer_3 = A2;
int Potentiometer_4 = A3;
int switch1 = 7;
int switch2 = 8;
int switch3 = 9;


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////Variables you must change according to your values/////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Add your data: SSID + KEY + host + location + id + password
//////////////////////////////////////////////
const char SSID_ESP[] = "UPCblabla";         //Give EXACT name of your WIFI
const char SSID_KEY[] = "secret";             //Add the password of that WIFI connection
const char* host = "http://domeniu.com";  //Add the host without "www" Example: electronoobs.com
String NOOBIX_id = "1900";                     //This is the ID you have on your database, I've used 99999 becuase there is a maximum of 5 characters
String NOOBIX_password = "secret";               //Add the password from the database, also maximum 5 characters and only numerical values
String location_url = "/TX.php?id=";            //location of your PHP file on the server. In this case the TX.php is directly on the first folder of the server
                                                //If you have the files in a different folder, add thas as well, Example: "/ESP/TX.php?id="     Where the folder is ESP
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////




//Used variables in the code
String url = "";
String URL_withPacket = "";   
unsigned long multiplier[] = {1,10,100,1000,10000,100000,1000000,10000000,100000000,1000000000};
//MODES for the ESP
const char CWMODE = '1';//CWMODE 1=STATION, 2=APMODE, 3=BOTH
const char CIPMUX = '1';//CWMODE 0=Single Connection, 1=Multiple Connections


//Define the used functions later in the code, thanks to Kevin Darrah, YT channel:  https://www.youtube.com/user/kdarrah1234
boolean setup_ESP();
boolean read_until_ESP(const char keyword1[], int key_size, int timeout_val, byte mode);
void timeout_start();
boolean timeout_check(int timeout_ms);
void serial_dump_ESP();
boolean connect_ESP();
void connect_webhost();
unsigned long timeout_start_val;
char scratch_data_from_ESP[20];//first byte is the length of bytes
char payload[200];
byte payload_size=0, counter=0;
char ip_address[16];


/////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////
//Variable to SEND to the DATABASE
bool sent_bool_1 = 0;
bool sent_bool_2 = 0;
bool sent_bool_3 = 0;
int  sent_nr_1 = 0;
int  sent_nr_2 = 0;
int  sent_nr_3 = 0;
int  sent_nr_4 = 0;
int  sent_nr_5 = 0;

//Variable RECEIVED from the DATABASE
bool received_bool_1 = 0;
bool received_bool_2 = 0;
bool received_bool_3 = 0;
bool received_bool_4 = 0;
bool received_bool_5 = 0;
int  received_nr_1 = 0;
int  received_nr_2 = 0;
int  received_nr_3 = 0;
int  received_nr_4 = 0;
int  received_nr_5 = 0;
String received_text = "";


/////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////



//Store received chars in this variables
char t1_from_ESP[5];  //For time from web
char d1_from_ESP[2];  //For received_bool_2
char d2_from_ESP[2];  //For received_bool_2
char d3_from_ESP[2];  //For received_bool_3
char d4_from_ESP[2];  //For received_bool_4
char d5_from_ESP[2];  //For received_bool_5
char d9_from_ESP[6];  //For received_nr_1
char d10_from_ESP[6]; //For received_nr_2
char d11_from_ESP[6]; //For received_nr_3
char d12_from_ESP[6]; //For received_nr_4
char d13_from_ESP[6]; //For received_nr_5
char d14_from_ESP[300]; //For received_text


//DEFINE KEYWORDS HERE
const char keyword_OK[] = "OK";
const char keyword_Ready[] = "Ready";
const char keyword_no_change[] = "no change";
const char keyword_blank[] = "#&";
const char keyword_ip[] = "192.";
const char keyword_rn[] = "\r\n";
const char keyword_quote[] = "\"";
const char keyword_carrot[] = ">";
const char keyword_sendok[] = "SEND OK";
const char keyword_linkdisc[] = "Unlink";

const char keyword_t1[] = "t1";
const char keyword_b1[] = "b1";
const char keyword_b2[] = "b2";
const char keyword_b3[] = "b3";
const char keyword_b4[] = "b4";
const char keyword_b5[] = "b5";
const char keyword_n1[] = "n1";
const char keyword_n2[] = "n2";
const char keyword_n3[] = "n3";
const char keyword_n4[] = "n4";
const char keyword_n5[] = "n5";
const char keyword_n6[] = "n6";
const char keyword_doublehash[] = "##";


SoftwareSerial ESP8266(ESP8266_RX, ESP8266_TX);// rx tx



void setup(){//        SETUP     START

  lcd.init();                 //Init the LCD
  lcd.backlight();            //Activate backlight  
 
  //Pin Modes for ESP TX/RX
  pinMode(ESP8266_RX, INPUT);
  pinMode(ESP8266_TX, OUTPUT);
 
  pinMode(LED1, OUTPUT);
  pinMode(LED2, OUTPUT);
  pinMode(LED3, OUTPUT);
  pinMode(LED4, OUTPUT);
  pinMode(LED5, OUTPUT);

  pinMode(Potentiometer_1, INPUT);
  pinMode(Potentiometer_2, INPUT);
  pinMode(Potentiometer_3, INPUT);
  pinMode(Potentiometer_4, INPUT);

  pinMode(switch1, INPUT);
  pinMode(switch2, INPUT);
  pinMode(switch3, INPUT);
   
 
  digitalWrite(LED1,LOW);
  digitalWrite(LED2,LOW);
  digitalWrite(LED3,LOW);
  digitalWrite(LED4,LOW);
  digitalWrite(LED5,LOW);
 

 
  ESP8266.begin(9600);//default baudrate for ESP
  ESP8266.listen();//not needed unless using other software serial instances
  Serial.begin(9600); //for status and debug
 
  delay(2000);//delay before kicking things off
  setup_ESP();//go setup the ESP

}




void loop(){

  sent_nr_1 = analogRead(Potentiometer_1);
  sent_nr_1 = analogRead(Potentiometer_2);
  sent_nr_1 = analogRead(Potentiometer_3);
  sent_nr_1 = analogRead(Potentiometer_4);
 
  sent_bool_1 = digitalRead(switch1);
  sent_bool_2 = digitalRead(switch2);
  sent_bool_3 = digitalRead(switch3);
 
  send_to_server_1();
  digitalWrite(LED1,received_bool_1);
  digitalWrite(LED2,received_bool_2);
  digitalWrite(LED3,received_bool_3);
  digitalWrite(LED4,received_bool_4);
  digitalWrite(LED5,received_bool_5); 

  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("N1: "); lcd.print(received_nr_1); lcd.print("  N2: "); lcd.print(received_nr_2);
  lcd.setCursor(0,1);
  lcd.print("N3: "); lcd.print(received_nr_3); lcd.print("  N4: "); lcd.print(received_nr_4);   
  delay(1000);//5 seconds between tries 


  /*
  send_to_server_2();
  digitalWrite(LED1,received_bool_1);
  digitalWrite(LED2,received_bool_2);
  digitalWrite(LED3,received_bool_3);
  digitalWrite(LED4,received_bool_4);
  digitalWrite(LED5,received_bool_5);

  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("N1: "); lcd.print(received_nr_1); lcd.print("  N2: "); lcd.print(received_nr_2);
  lcd.setCursor(0,1);
  lcd.print("N3: "); lcd.print(received_nr_3); lcd.print("  N4: "); lcd.print(received_nr_4); 
  delay(1000);
  send_to_server_3();
  digitalWrite(LED1,received_bool_1);
  digitalWrite(LED2,received_bool_2);
  digitalWrite(LED3,received_bool_3);
  digitalWrite(LED4,received_bool_4);
  digitalWrite(LED5,received_bool_5);

  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("N1: "); lcd.print(received_nr_1); lcd.print("  N2: "); lcd.print(received_nr_2);
  lcd.setCursor(0,1);
  lcd.print("N3: "); lcd.print(received_nr_3); lcd.print("  N4: "); lcd.print(received_nr_4); 
  delay(1000);
  send_to_server_4();
  digitalWrite(LED1,received_bool_1);
  digitalWrite(LED2,received_bool_2);
  digitalWrite(LED3,received_bool_3);
  digitalWrite(LED4,received_bool_4);
  digitalWrite(LED5,received_bool_5);

  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("N1: "); lcd.print(received_nr_1); lcd.print("  N2: "); lcd.print(received_nr_2);
  lcd.setCursor(0,1);
  lcd.print("N3: "); lcd.print(received_nr_3); lcd.print("  N4: "); lcd.print(received_nr_4);  
  delay(1000);
  */

 
  send_to_server_5();
  digitalWrite(LED1,received_bool_1);
  digitalWrite(LED2,received_bool_2);
  digitalWrite(LED3,received_bool_3);
  digitalWrite(LED4,received_bool_4);
  digitalWrite(LED5,received_bool_5);
 

 
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print(received_text);
 
  delay(1000);

}//End of the main loop

cod esp8266

  • boolean setup_ESP(){//returns a '1' if successful
     
      ESP8266.print("AT\r\n");// Send just 'AT' to make sure the ESP is responding
      //this read_until_... function is used to find a keyword in the ESP response - more on this later and in the function itself
      if(read_until_ESP(keyword_OK,sizeof(keyword_OK),5000,0))//go look for keyword "OK" with a 5sec timeout
        Serial.println("ESP CHECK OK");
      else
        Serial.println("ESP CHECK FAILED");
      serial_dump_ESP();//this just reads everything in the buffer and what's still coming from the ESP

       ESP8266.print("AT+RST\r\n");// Give it a reset - who knows what condition it was in, better to start fresh
      if(read_until_ESP(keyword_OK,sizeof(keyword_OK),5000,0))//go look for keyword "Ready" - takes a few seconds longer to complete
        Serial.println("ESP RESET OK");//depneding on the FW version on the ESP, sometimes the Ready is with a lowercase r - ready
      else
        Serial.println("ESP RESET FAILED");
      serial_dump_ESP();

     
       ESP8266.print("AT+CWMODE=");// set the CWMODE
       ESP8266.print(CWMODE);//just send what is set in the constant
       ESP8266.print("\r\n");
      if(read_until_ESP(keyword_OK,sizeof(keyword_OK),5000,0))//go look for keyword "OK"
        Serial.println("ESP CWMODE SET");
      else
        Serial.println("ESP CWMODE SET FAILED"); //probably going to fail, since a 'no change' is returned if already set - would be nice to check for two words
      serial_dump_ESP(); 
      
       //Here's where the SSID and PW are set
       ESP8266.print("AT+CWJAP=\"");// set the SSID AT+CWJAP="SSID","PW"
       ESP8266.print(SSID_ESP);//from constant
       ESP8266.print("\",\"");
       ESP8266.print(SSID_KEY);//form constant
       ESP8266.print("\"\r\n");
      if(read_until_ESP(keyword_OK,sizeof(keyword_OK),10000,0))//go look for keyword "OK"
        Serial.println("ESP SSID SET OK");
      else
        Serial.println("ESP SSID SET FAILED");  
      serial_dump_ESP();
     
      //This checks for and stores the IP address
      Serial.println("CHECKING FOR AN IP ADDRESS");
      ESP8266.print("AT+CIFSR\r\n");//command to retrieve IP address from ESP
      if(read_until_ESP(keyword_rn,sizeof(keyword_rn),10000,0)){//look for first \r\n after AT+CIFSR echo - note mode is '0', the ip address is right after this
      if(read_until_ESP(keyword_rn,sizeof(keyword_rn),1000,1)){//look for second \r\n, and store everything it receives, mode='1'
        //store the ip adress in its variable, ip_address[]
        for(int i=1; i<=(scratch_data_from_ESP[0]-sizeof(keyword_rn)+1); i++)//that i<=... is going to take some explaining, see next lines
           ip_address[i] = scratch_data_from_ESP[i];//fill up ip_address with the scratch data received
    //i=1 because i=0 is the length of the data found between the two keywords, BUT this includes the length of the second keyword, so i<= to the length minus
    //size of teh keyword, but remember, sizeof() will return one extra, which is going to be subtracted, so I just added it back in +1
        ip_address[0] = (scratch_data_from_ESP[0]-sizeof(keyword_rn)+1);//store the length of ip_address in [0], same thing as before
        Serial.print("IP ADDRESS = ");//print it off to verify
        for(int i=1; i<=ip_address[0]; i++)//send out the ip address
        Serial.print(ip_address[i]);
        Serial.println("");
      }}//if first \r\n
      else
      Serial.print("IP ADDRESS FAIL");
      serial_dump_ESP();


       ESP8266.print("AT+CIPMUX=");// set the CIPMUX
       ESP8266.print(CIPMUX);//from constant
       ESP8266.print("\r\n");
      if(read_until_ESP(keyword_OK,sizeof(keyword_OK),5000,0))//go look for keyword "OK" or "no change
        Serial.println("ESP CIPMUX SET");
      else
        Serial.println("ESP CIPMUX SET FAILED");
      serial_dump_ESP();




     //that's it!  Could be done by nesting everything together, so if one thing fails, it returns '0', and if it gets all the way through it returns '1'...oh well
     
     
    }//setup ESP

vineri, 26 iulie 2019

The Great Hack sau cum sunt folosite informatiile de pe retelele de socialiare

Am scris mai demult despre chestia asta... si da, mi-am dat seama la acea vreme unde o sa duca tot tambalaul asta cu "big data" si profilul "o.c.e.a.n.". :D Cand a aparut facebook-ul, eu aveam acest blog de ceva timp. (care mergea chiar bine conform trafic.ro de la acea vreme)

luni, 27 mai 2019

Critica de film plus bonus un film asa si asa

Pai vezi ma ca pana nu iti explica mura in gura nu intelegi?
Degeaba te uiti la stive de filme romanesti, asa cum fac eu, pt ca de fapt...

dar sa ne luminam, "copiii soarelui.."  o expresie din filmul  "E atat de aproape fericirea", expresie pe care o sa o notez in carnetelul cu expresii frumoase. :) 

marți, 16 aprilie 2019

Pai cand faceam noi repetoare, altii se jucau cu lopatelele

Am gasit in strafundul google backup photos, niste poze din epoca bronzului si a germaniului, cand faceam parte dintr-o gasca care repara, intretinea, si monta noi repetoare in partea de S-E a Romaniei.

Nu stiu daca o sa am timp sa bag explicatii la fiecare poza, dar in mare, orice plecare la vreun repetor, se stabilea si se punea la punct "La Grasele". Era o bodega vai de capul ei in Militari, unde ne strangeam gasca care mergea pe la repetoare.

luni, 15 aprilie 2019

sa vezi ce boxe Jazz mi-am revergorat

 la ora scrierii acestei postari, boxele functioneaza deja de vreo luna si ceva. dar nu'i nimic, mai bine sa postez mai tarziu, decat nici o data...


reparatie cooler laptop Dell

habar nu stiu ce model de laptop Dell era, dar cert este ca avea coolerul defect si intra in protectie.







reparatie Grundig 440

Pe masa de operatie, un Grundig 440, combina compacta old-school. Final STK461 2x30w reali, decedat pe un canal. S-a procedat la extractia integratului. Acum asteptam Adelaida.ro 😊😁😄 Ca un fapt divers, ambutisarile si tablele sunt facute si pt module separate, deck, amplituner, pickup. Dar acest model "compact center", le contine pe toate. 😉


reparatie camera supraveghere

repede postare:

am facut rost de la cineva de o camera de supraveghere defecta.
ce avea defect? cineva a uitat un holsurub de la demontare in ea, si holsurubul s-a plimbat pe placa de alimentare in zona unui convertor dc-dc, si a facut de asa natura, incat sa faca scurt pe o bobina mica smd.

inca un monitor reparat

repede postare:

am facut rost de un monitor cel putin interesant, pt ca are pe langa intrarea VGA, inca doua intrari composit pe BNC, 2 intrari audio, o intrare svideo, si o intrare RS485. mda dubios asa am zis si eu.
inca o parte misto, are o sursa in comutatie, care scoate pur si simplu, decat 12 volti pt tot monitorul.
eu i-am pus inca un buton, si il pot alimenta si de la o baterie de 12 volti. (de pe panourile fotovoltaice)