#author("2021-12-05T13:40:23+09:00","default:Real2Virtual202111","Real2Virtual202111")
#author("2021-12-06T13:18:23+09:00","default:Real2Virtual202111","Real2Virtual202111")
[[Real2Virtual202111]]

#code(c){{

/*
  m5atom-wifi-ex03 by Takashi Yamanoue,
  Based on the WiFiAccessPoint.ino
  Created for arduino-esp32 on 04 July, 2018
  by Elochukwu Ifediora (fedy0)
*/

#include <WiFi.h>
#include <WiFiClient.h>
#include <WiFiAP.h>
#include "M5Atom.h"
//#include <SoftwareSerial.h>

#define LED_BUILTIN 2   // Set the GPIO pin where you connected your test LED or comment this line out if your dev board has a built-in LED

// Set these to your desired credentials.
const char *ssid = "YAMA-ATOM5-EX01";
const char *password = "12345678";
/*
IPAddress ip(192,168,4,2);
IPAddress gateway(192,168,4,1);
IPAddress subnet(255,255,255,0);
IPAddress DNS(192,168,4,1);
*/
WiFiServer server(23);

//Serial1 mySerial(22,19);  //rx, tx

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);

  Serial.begin(115200);
  Serial.println();
  Serial.println("Configuring access point...");

//  WiFi.config(ip,gateway,subnet,DNS);

  // You can remove the password parameter if you want the AP to be open.
  WiFi.softAP(ssid, password);
  IPAddress myIP = WiFi.softAPIP();
  Serial.print("AP IP address: ");
  Serial.println(myIP);
  server.begin();

  Serial.println("Server started");

  Serial2.begin(9600,SERIAL_8N1,22,19);
  Serial2.println("Server started, serial1");
}

void loop() {
  WiFiClient client = server.available();   // listen for incoming clients

  if (client) {                             // if you get a client,
    Serial.println("New Client.");           // print a message out the serial port
    String currentLine = "";                // make a String to hold incoming data from the client
    while (client.connected()) {            // loop while the client's connected
      if (client.available()) {             // if there's bytes to read from the client,
        char c = client.read();             // read a byte, then
        Serial.write(c);                    // print it out the serial monitor
        Serial2.write(c);
        
        if (c == '\n') {                    // if the byte is a newline character

          // if the current line is blank, you got two newline characters in a row.
          // that's the end of the client HTTP request, so send a response:
          if (currentLine.length() == 0) {
            
          } else {    // if you got a newline, then clear currentLine:
            currentLine = "";
          }
        } else if (c != '\r') {  // if you got anything else but a carriage return character,
          currentLine += c;      // add it to the end of the currentLine
        }
      }
      if(Serial.available()){
        char c= Serial.read();
        Serial2.write(c);
        client.write(c);
      }
      if(Serial2.available()){
        char c=Serial2.read();
        Serial.write(c);
        client.write(c);
      }
    }
    // close the connection:
    client.stop();
    Serial.println("Client Disconnected.");
  }
}

}}
----
#counter



トップ   編集 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS