Click here to Skip to main content
15,393,377 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
<code><code><code><code><code><code><code><code><code><code><code>
C++



What I have tried:

#include <mfrc522.h>
#include <spi.h>
#include <esp8266httpclient.h>
#include <esp8266wifi.h>

//Network SSID
const char* ssid = "EE";
const char* password = "Erlangga23";

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

#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.193.48/absensi/ubahmode.php";
String http.begin('url, 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.193.48/absensi/kirimkartu.php?nokartu=" idtag;
="" http.begin("url="" link");

="" httpcode="http.GET();
" payload="http.getString();
" serial.println(payload);
="" http.end();

="" delay(2000);<="" pre="">
Posted
Updated 8-Jan-22 20:34pm

1 solution

We have no idea.
Partly because what you have posted isn't complete, partly because it is corrupt, and partly because you haven't given us any real information, just dumped your whole code on us and hoped we would read the lot and look for an error somewhere.

That won't work: it's also thoughtless, lazy, and rude - would you like it if I dumped the whole of my project on you and said "it don't work - fix it for me"?
Of course you wouldn't - you have no idea what the problem might be, much less where in the code it is.

But you can solve this yourself, or at the very least give us the right information to be able to help you.
From your subject title, it's a syntax error: "Expected initializer before '.' token" but if you look closely at the error message, there will be more information there: the file name, the line number, and almost certainly the line on which the error was found.
So edit that file, go to that line (Most editors support CTRL+G to go directly to a line number) and look at it in context with a couple of lines above and below - because quite often an error is caused by something close, but not actually on the line it's reported.

"Expected initializer before '.' token" just means that it found code that didn't make sense to it - the "." character isn't legal there.
This can be caused by something like this:
C++
void foo()
   {
   int bar.dee = 666;
   }
Where the line is declaring a variable with a "." in the name, which is illegal because "." is an operator, and you can't declare a "multipart" variabel like that in C.

So have a look at the error message, reference the line it is being reported on, and see if you can work it out.
If you can't then show us the line, the error message, and the function it is part of rather than your whole code!
And format it! When you paste code, you are given options for how you want to paste it, one of which is "code block" - use that, and HTML characters such as "<" and ">" do not mess up the formatting and preserve your original indentation. And prevent you code from being corrupted and unreadable ...
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900