Bro, i got stuck with my code. can you solve this code to connecting to website

#include <SPI.h>
#include <MFRC522.h>

#include <ESP8266HTTPClient.h>
#include <ESP8266WiFi.h>

//Network SSID
const char* ssid = "you are";
const char* password = "abi12345";

//pengenal host (server) = IP Address komputer server
const char* host = "192.168.43.22";

#define LED_PIN 15 //D8
#define BTN_PIN 5 //D1

//sediakan variabel untuk RFID
#define SDA_PIN 2 //D4
#define RST_PIN 0 //D3

MFRC522 mfrc522(SDA_PIN, RST_PIN);

void setup() {
Serial.begin(9600);

//setting koneksi wifi
WiFi.hostname("NodeMCU");
WiFi.begin(ssid, password);

//cek koneksi wifi
while(WiFi.status() != WL_CONNECTED)
{
//progress sedang mencari WiFi
delay(500);
Serial.print(".");
}

Serial.println("Wifi Connected");
Serial.println("IP Address : ");
Serial.println(WiFi.localIP());

pinMode(LED_PIN, OUTPUT);
pinMode(BTN_PIN, OUTPUT);

SPI.begin();
mfrc522.PCD_Init();
Serial.println("Dekatkan Kartu RFID Anda ke Reader");
Serial.println();
}

void loop() {
//baca status pin button kemudian uji
if(digitalRead(BTN_PIN)==1) //ditekan
{
Serial.println("OK");
//nyalakan lampu LED
digitalWrite(LED_PIN, HIGH);
while(digitalRead(BTN_PIN)==1) ; //menahan proses sampai tombol dilepas
//ubah mode absensi di aplikasi web
String getData, Link ;
HTTPClient http ;
//Get Data
Link = "http://192.168.43.22/absensi/ubahmode.php";
http.begin(Link);

 int httpCode = http.GET();
 String payload = http.getString();

 Serial.println(payload);
 http.end();

}

//matikan lampu LED
digitalWrite(LED_PIN, LOW);

if(! mfrc522.PICC_IsNewCardPresent())
return ;

if(! mfrc522.PICC_ReadCardSerial())
return ;

String IDTAG = "";
for(byte i=0; i<mfrc522.uid.size; i++)
{
IDTAG += mfrc522.uid.uidByte[i];
}

//nyalakan lampu LED
digitalWrite(LED_PIN, HIGH);

//kirim nomor kartu RFID untuk disimpan ke tabel tmprfid
WiFiClient client;
const int httpPort = 80;
if(!client.connect(host, httpPort))
{
Serial.println("Connection Failed");
return;
}

String Link;
HTTPClient http;
Link = "http://192.168.43.22/absensi/kirimkartu.php?nokartu=" + IDTAG;
http.begin(Link);

int httpCode = http.GET();
String payload = http.getString();
Serial.println(payload);
http.end();

delay(2000);
}

Your post was MOVED to its current location as it is more suitable.

Could you also take a few moments to Learn How To Use The Forum.

Other general help and troubleshooting advice can be found here.
It will help you get the best out of the forum in the future.


Why do users choose to ignore the advice on posting code ?

The easier you make it to read and copy your code the more likely it is that you will get help

Please follow the advice given in the link below when posting code , use code tags and post the code here

you should describe in detail what part of your code works and which part does not work.

You should add serial output to your code and then post the serial output as a code-section.

You should post code by using code-tags
There is an automatic function for doing this in the Arduino-IDE
just three steps

  1. press Ctrl-T for autoformatting your code
  2. do a rightclick with the mouse and choose "copy for forum"
  3. paste clipboard into write-window of a posting

best regards Stefan

oo i see, thank you sir

thank you stefan. this is my first time using this blog so i'm a newbie

salam seperkontolan

So, are you going to post your code in the preferred way ?

Your code contains

connecting to a wifi-network

reading a RFID-card

doing things with http

What seems strange to me is:
creating a http-object each time the if-condition becomes true.
I guess this should be in void setup

    String getData, Link ;
    HTTPClient http ;
 

using variables of type String in this way eats up all memory over time and will make your porgram crash
you should avoid vraiabletype String until you really know how to use them
use SafeString or PString instead

For more help you have to post a new code-version as a code-section
and a description what your program does and what not.

best regards Stefan

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.