Use this forum to chat about hardware specific topics for the ESP8266 (peripherals, memory, clocks, JTAG, programming)

User avatar
By Kunal2795
#64206
Code: Select all#include <Keypad.h>
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
#include <LiquidCrystal_I2C.h>

const byte ROWS = 4; //four rows
const byte COLS = 3; //four columns


//define the cymbols on the buttons of the keypads
char hexaKeys[ROWS][COLS] = {
    {'1','2','3'},
    {'4','5','6'},
    {'7','8','9'},
    {'*','0','#'}
};

byte rowPins[ROWS] = {16, 5, 4, 14}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {12, 13, 3}; //connect to the column pinouts of the keypad

Keypad cusomKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);

const char* ssid = "Moto";
const char* password = "kkk12345";

LiquidCrystal_I2C lcd(0x3F, 16, 2);
WiFiUDP Udp;

unsigned int localUdpPort = 4210;  // local port to listen on
char incomingPacket[255];  // buffer for incoming packets
char  replyPacekt[] = "Hi there! Got the message :-)";  // a reply string to send back

void setup() {

    // put your setup code here, to run once:
    Serial.begin(115200);
    Serial.println();

    lcd.begin(16,2);
    lcd.init();
    lcd.backlight();

    // Move the cursor characters to the right and
    // zero characters down (line 1).
    lcd.setCursor(1, 0);
    Serial.printf("Connecting to %s ", ssid);

    WiFi.begin(ssid,password);

    while (WiFi.status() != WL_CONNECTED)
    {
        delay(500);
        Serial.print(".");
    }

    Serial.println(" connected");

    String s=WiFi.localIP().toString().c_str();

    Udp.begin(localUdpPort);

    Serial.printf("Now listening at IP %s, UDP port %d\n", WiFi.localIP().toString().c_str(), localUdpPort);

    lcd.print(s);
    lcd.setCursor(5,1);
    lcd.print(localUdpPort);
}

void loop() {
    // put your main code here, to run repeatedly:
    int packetSize = Udp.parsePacket();

    if (packetSize)
    {
        // receive incoming UDP packets
        Serial.printf("Received %d bytes from %s, port %d\n", packetSize, Udp.remoteIP().toString().c_str(), Udp.remotePort());

        int len = Udp.read(incomingPacket, 255);
        if (len > 0)
        {
            incomingPacket[len] = 0;
        }

        Serial.printf("UDP packet contents: %s\n", incomingPacket);

        lcd.clear();
        lcd.setCursor(1,0);
        lcd.print(incomingPacket);

        // send back a reply, to the IP address and port we got the packet from
        Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
        Udp.write(replyPacekt);
        Udp.endPacket();

        char customKey = cusomKeypad.getKey();

        lcd.clear();
        lcd.print(customKey);

        if (customKey != NO_KEY){
            Serial.println(customKey);
        }
    }
}


Errors:

*Arduino: 1.8.1 (Windows 10), Board: "NodeMCU 1.0 (ESP-12E Module), 80 MHz, 115200, 4M (3M SPIFFS)"
Build options changed, rebuilding all
In file included from sketch\Mix.ino.cpp:1:0:
C:\Users\mahe\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.3.0\cores\esp8266/Arduino.h:42:14: error: expected identifier before numeric constant
#define HIGH 0x1
^

C:\Users\mahe\Documents\Arduino\libraries\Keypad\src/Keypad.h:56:16: note: in expansion of macro 'HIGH'
#define CLOSED HIGH
^

C:\Users\mahe\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.3.0\libraries\ESP8266WiFi\src/include/wl_definitions.h:73:3: note: in expansion of macro 'CLOSED'
CLOSED = 0,
^

C:\Users\mahe\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.3.0\cores\esp8266/Arduino.h:42:14: error: expected '}' before numeric constant
#define HIGH 0x1
^

C:\Users\mahe\Documents\Arduino\libraries\Keypad\src/Keypad.h:56:16: note: in expansion of macro 'HIGH'
#define CLOSED HIGH
^

C:\Users\mahe\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.3.0\libraries\ESP8266WiFi\src/include/wl_definitions.h:73:3: note: in expansion of macro 'CLOSED'
CLOSED = 0,
^

C:\Users\mahe\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.3.0\cores\esp8266/Arduino.h:42:14: error: expected unqualified-id before numeric constant
#define HIGH 0x1
^

C:\Users\mahe\Documents\Arduino\libraries\Keypad\src/Keypad.h:56:16: note: in expansion of macro 'HIGH'
#define CLOSED HIGH
^

C:\Users\mahe\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.3.0\libraries\ESP8266WiFi\src/include/wl_definitions.h:73:3: note: in expansion of macro 'CLOSED'
CLOSED = 0,
^

In file included from C:\Users\mahe\Documents\Arduino\Mix\Mix.ino:2:0:
C:\Users\mahe\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.3.0\libraries\ESP8266WiFi\src/ESP8266WiFi.h:29:1: error: expected declaration before '}' token
}
^
exit status 1
Error compiling for board NodeMCU 1.0 (ESP-12E Module).*
esp8266