Advertisement
Guest User

Untitled

a guest
Apr 26th, 2018
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. #include <ESP8266HTTPClient.h>
  2. #include <ESP8266WiFi.h>
  3.  
  4. const char* ssid = "EUCinternet";
  5. const char* pass = NULL;
  6. const char* dest = "quickbillet.dk";
  7.  
  8. int WiFiCon() {
  9. int xCnt = 0;
  10. if (WiFi.status() != WL_CONNECTED){
  11. WiFi.mode(WIFI_STA);
  12. WiFi.begin(ssid, pass);
  13.  
  14. while (WiFi.status() != WL_CONNECTED && xCnt < 50) {
  15. delay(500);
  16. xCnt ++;
  17. }
  18.  
  19. if (WiFi.status() != WL_CONNECTED){
  20. return 0; //never connected
  21. } else {
  22. return 1; //1 is initial connection
  23. }
  24. } else {
  25. return 2; //2 is already connected
  26. }
  27. }
  28. void setup() {
  29. Serial.begin(1200);
  30. while(WiFi.status() != WL_CONNECTED) {
  31. WiFiCon();
  32. }
  33. }
  34. void loop() {
  35. if(WiFi.status()== WL_CONNECTED){
  36. HTTPClient http;
  37. http.begin("https://quickbillet.dk/ESP/req.php","CB:BD:10:61:FF:4C:5A:52:0F:B1:DD:73:4F:40:D8:09:6E:BF:A4:9F");
  38. http.addHeader("Content-Type", "application/x-www-form-urlencoded");
  39. int responseCode = http.POST("title=foo&body=bar&userId=1");
  40. String payload = http.getString();
  41.  
  42. char temp[10];
  43. payload.toCharArray(temp, 10);
  44.  
  45. Serial.write(temp);
  46. http.end();
  47. }else{ }
  48. delay(10000); //Send a request every 10 seconds
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement