Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <WiFiClient.h>
- #include <ESP8266WebServer.h>
- #include <ESP8266mDNS.h>
- #include <ESP8266WiFiMulti.h>
- #include <ESP8266HTTPClient.h>
- #include <string.h>
- const char* ssidS = "" ;
- const char* passwordS = "";
- //String Adres = "http://sag-wataha.org.pl/wataha/dane_zapis.php?";
- HTTPClient http;
- int polaczenie = 0 ;
- String fun = "" ;
- String wiadomosc = "" ;
- void setup() {
- WiFi.disconnect();
- Serial.begin(9600);
- Serial.flush();
- Serial.println("");
- }
- void loop() {
- if (polaczenie == 1) {
- if (WiFi.status() != WL_CONNECTED) szukajwifi(ssidS , passwordS );
- }
- if (Serial.available())
- {
- String Dane_atmega = Serial.readString();
- if (Dane_atmega.length() > 3 ) {
- fun = Dane_atmega[0] ;
- fun += Dane_atmega[1];
- Serial.println(fun);
- }
- if ( fun == "01") {
- //Serial.println("wybieram fun 1");
- int ileznakow = Dane_atmega.length() ;
- int jaki = 0 ;
- String dzielnik = "_" ;
- String ssidf = "";
- String passf = "";
- for (int a = 2 ; a < ileznakow ; a++)
- {
- if ((Dane_atmega[a]) == dzielnik[0] ) {
- jaki = 1 ;
- continue ;
- }
- if (jaki == 0) {
- ssidf += Dane_atmega[a] ;
- }
- if (jaki == 1 ) {
- passf += Dane_atmega[a] ;
- }
- }
- szukajwifi(ssidf , passf ) ;
- }
- else if ( fun == "02") {
- //Serial.println("wybieram fun 1");
- int ileznakow = Dane_atmega.length() ;
- for (int a = 2 ; a < ileznakow ; a++)
- {
- wiadomosc += Dane_atmega[a] ;
- }
- dodajdobazydanuch (wiadomosc ) ;
- wiadomosc = "";
- }
- else if ( fun == "03") {
- //Serial.println("wybieram fun 1");
- int ileznakow = Dane_atmega.length() ;
- for (int a = 2 ; a < ileznakow ; a++)
- {
- wiadomosc += Dane_atmega[a] ;
- }
- odczytaja_z_bazy (wiadomosc ) ;
- wiadomosc = "";
- }
- else {
- Serial.println("funkcja nie zaimplementowana") ;
- }
- }
- }
- void szukajwifi( String ssid , String password ) {
- ssidS = ssid.c_str() ;
- passwordS = password.c_str() ;
- //passwordS = password ;
- WiFi.disconnect();
- delay(200);
- WiFi.mode(WIFI_STA);
- WiFi.begin(ssidS, passwordS);
- Serial.println("rozlaczony, szukam sieci...");
- while (WiFi.status() != WL_CONNECTED) {
- delay(200);
- // Serial.print(".");
- }
- Serial.println(" ");
- Serial.println("Polaczony z siecia");
- Serial.println(WiFi.localIP());
- //Serial.println("OK");
- fun = "" ;
- wiadomosc = "" ;
- polaczenie = 1 ;
- }
- void dodajdobazydanuch ( String Dane_atmega ) {
- String URL_dodania = Dane_atmega ;
- Serial.println(URL_dodania);
- http.begin(URL_dodania);
- int httpCode = http.GET();
- delay (10);
- http.end();
- URL_dodania = "" ;
- }
- void odczytaja_z_bazy ( String Dane_atmega ) {
- String URL_dodania = Dane_atmega ;
- String dzielnik = "&" ;
- //Serial.println(URL_dodania);
- http.begin(URL_dodania);
- int httpCode = http.GET();
- String payload = http.getString();
- /// jesli chcesz przesylac calego stringa danych do atmegi to odkomentuj
- Serial.println(payload);
- ///////////////////////--------------------------------------------\\\\\\\\\\\\\\\\\\\\\\\\\\\\
- delay (5);
- http.end();
- URL_dodania = "" ;
- /// jesli chcesz przesylac calego stringa danych do atmegi to usun lub zakomentuj pod spodem wszystko
- // int jaki = 0 ;
- // String calosc [10];
- // int ileznakow = payload.length() ;
- // for (int a = 0 ; a < ileznakow ; a++)
- // {
- // if ((payload[a]) == dzielnik[0] ) {
- // Serial.println(calosc[jaki]) ;
- // jaki ++ ;
- // continue ;
- // }
- // calosc[jaki] += payload[a] ;
- // }
- ///////////////////////--------------------------------------------\\\\\\\\\\\\\\\\\\\\\\\\\\\\
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement