MAGCARI

WiFi and UART

May 18th, 2023
1,077
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <SoftwareSerial.h>
  2. #include <ESP8266WiFi.h>
  3. #include <FirebaseESP8266.h>
  4.  
  5. EspSoftwareSerial::UART testSerial;
  6.  
  7. // WiFi credentials
  8. const char* ssid = "no internet";
  9. const char* password = "nointernet";
  10.  
  11. void setup() {
  12.   Serial.begin(9600);
  13.  
  14.   // Connect to Wi-Fi
  15.   WiFi.begin(ssid, password);
  16.  
  17.   while (WiFi.status() != WL_CONNECTED) {
  18.     delay(1000);
  19.     Serial.print(".");
  20.   }
  21.  
  22.   Serial.println("");
  23.   Serial.println("WiFi connected");
  24.   Serial.print("IP address: ");
  25.   Serial.println(WiFi.localIP());
  26.  
  27.   testSerial.begin(115200, EspSoftwareSerial::SWSERIAL_8N1, D7, D8, false, 95, 11);
  28.   if(!testSerial){
  29.     Serial.println("Invalid EspSoftwareSerial pin configuration, check config");
  30.     while(1){
  31.       delay(1000);
  32.     }
  33.   }
  34.   Serial.println("EspSoftwareSerial init");
  35. }
  36.  
  37. void loop(){
  38.   if(testSerial.available()){
  39.     char receivedData = testSerial.read();
  40.     Serial.println(receivedData);
  41.   }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment