Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <ESP8266WiFi.h>
- #include <ESP8266HTTPClient.h>
- //replace "ssid" with your WiFi SSID
- const char* ssid = "ssid";
- //replace "pass" with your WiFi Pass
- const char* pass = "pass";
- void setup () {
- // Serial monitor Baud Rate
- Serial.begin(115200);
- // Begin WiFI connect
- WiFi.begin(ssid, pass);
- // While wifi is not connected, print connecting every 1s (1000ms) to serial monitor.
- while (WiFi.status() != WL_CONNECTED)
- {
- delay(1000);
- Serial.println("Connecting ...");
- }
- //report WiFI Connected with IP address
- Serial.println(F(""));
- Serial.println(F("WiFi connected"));
- Serial.println();
- Serial.print(F("IP address is "));
- Serial.println(WiFi.localIP());
- // initialize digital pin LED_BUILTIN as an output.
- pinMode(LED_BUILTIN, OUTPUT);
- }
- // the loop function runs over and over again forever
- void loop() {
- //turn the LED on (LOW is the voltage level)
- digitalWrite(LED_BUILTIN, LOW);
- //input to project.rinaldo.id/esp8266
- inputweb("blinktest2",0,0,0,0,0,0,"ON","LOW","");
- //delay 1s
- delay(1000);
- //turn the LED of (HIGH is the voltage level)
- digitalWrite(LED_BUILTIN, HIGH);
- //input to project.rinaldo.id/esp8266
- inputweb("blinktest2",1,1,1,1,1,1,"OFF","HIGH","");
- //delay 1s
- delay(1000);
- }
- void inputweb(char identifier[255], float sensor1, float sensor2, float sensor3, float sensor4, float sensor5, float sensor6, char char1[], char char2[], char char3[])
- {
- //Check WiFi connection status
- if (WiFi.status() == WL_CONNECTED)
- {
- HTTPClient http; //Declare an object of class HTTPClient
- http.begin(String("http://project.rinaldo.id/esp8266/input.php?")
- + String("identifier=") + identifier
- + String("&sensor1=") + String(sensor1)
- + String("&sensor2=") + String(sensor2)
- + String("&sensor3=") + String(sensor3)
- + String("&sensor4=") + String(sensor4)
- + String("&sensor5=") + String(sensor5)
- + String("&sensor6=") + String(sensor6)
- + String("&char1=") + char1
- + String("&char2=") + char2
- + String("&char3=") + char3
- ); //Specify request destination
- int httpCode = http.GET(); //Send the request
- if (httpCode > 0) //Check the returning code
- {
- String payload = http.getString(); //Get the request response payload
- Serial.println("Server returned : ");
- Serial.println(payload); //Print the response payload from server
- }
- http.end(); //Close connection
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement