Using R4 WiFi for Wireless Serial Monitor?

Hi there,
Working with a student on an Arduino controlled Smart Greenhouse. We are using an R4 WiFi with hopes to use Serial Monitor over Wifi to track what is going on without needing a direct USB connection.

Is there a simple way to do this?

I assumed it would be all over the web by now, but none of my searches found even a mention of it yet. I'm assuming I just had the wrong keywords, as this seems like one of the most basic things to do with it. All the examples were for more complicated things.

Anyone have a link or basic instruction for this?

Thanks!
-Teacher Tom

1 Like

Why not run a webserver on the Arduino and access it using a browser to view whatever it is that you want to see ?

1 Like

TELNET

I do it all the time.

The example webserver code I saw didn't say anything about the Serial Monitor readout. Is there an example of how to do this somewhere?

Whay just IDE Serial monitor and not an existing terminal program?

I was suggesting using the webserver to serve the values to a browser on the PC so no Serial monitor is needed

What is the attraction of using the Serial monitor compared to viewing the data in a web browser ?

many like my TelnetStream library. you can find in Library Manager

1 Like

I don't know if this library works with the Arduino WiFi Rev 4.
The Arduino WiFi Rev 4 is still very new. This means there is not much available.

Telnet is an option or sending UDP-messages.
I have not used an Arduino WiFi REV (and I never will because it is too expensive compared to an ESP32)

If you can afford to spend another $10 to buy a ESP32-node-MCU-Board

this library surely works with ESP32-boards

look up this examples there is a paragraph about sending receiving UDP-messages

best regards Stefan

Sorry for the confusion, I mean the values that would be seen in serial monitor. They can be viewed in any format for this project, though the ability to send a serial command would be a nice bonus.

To clarify, is there example code to simple use the R4 as a local webserver and have it write out the serial.print commands in simple text format?

Same link. Paragrap Simple Webserver

There is a build in ESP32 on the R4 Wifi, so I'm assuming that should work. I'm new to the IoT webserver bit, so I think the missing connection in my head is the converting the Serial.print command to print onto the webserver page. Is it automatic, or is there an extra bit of code needed, and where do I look this up?

Is it as simple as changing Serial.print to Server.print? (and using the sample webserver code to make it a server)

Great! Thanks everyone for the help.
If anyone has a link to a good resource that helps provide examples of this I can give to my students that would be great!

I think that you are missing the point. What you can do is have the webserver serve HTML pages to the browser that contain the data that you want to display. This could be as simple as a list of numbers or a full blown web page with colour highlighting of significant values, tables of previous values, links to other pages etc, etc

Think of it as your own personal Internet holding data that you are interested in and presenting it in a meaningful way

buy them an ESP32-node-MCU.
They start at €6

For the ESP32 there is a real HUGE library collection. The ESP32 is the de-facto standard for WiFi
The WebSerial-library offers exactly what you are looking for.


It does not work with the Arduino Uno Rev 4. Because the R4 uses a different microcontroller.
Here is an example code

#include <Arduino.h>
#include <WiFi.h>
#include <AsyncTCP.h>
#include <ESPAsyncWebServer.h>
#include <WebSerial.h>

AsyncWebServer MyAsyncWebServer(80);

//const char *ssid     = "WLANBuero_EXT"; 
const char *ssid     = "your SSID"; 
const char *password = "your password";

int MyCounter = 0;

void PrintFileNameDateTime() {
  Serial.println("Code running comes from file ");
  Serial.println(__FILE__);
  Serial.print("  compiled ");
  Serial.print(__DATE__);
  Serial.print(" ");
  Serial.println(__TIME__);  
}


void WebPrintFileNameDateTime() {
  String FileInfo = "Code running comes from file ";
  FileInfo += __FILE__ ;
  FileInfo += "  compiled " ;
  FileInfo += __DATE__ ;
  FileInfo += " ";
  FileInfo += __TIME__;
  WebSerial.println(FileInfo);
}    

boolean TimePeriodIsOver (unsigned long &periodStartTime, unsigned long TimePeriod) {
  unsigned long currentMillis  = millis();  
  if ( currentMillis - periodStartTime >= TimePeriod ) {
    periodStartTime = currentMillis; // set new expireTime
    return true;                // more time than TimePeriod) has elapsed since last time if-condition was true
  } 
  else return false;            // not expired
}

unsigned long MyTestTimer = 0;                   // variables MUST be of type unsigned long
const byte    OnBoard_LED = 2;

void BlinkHeartBeatLED(int IO_Pin, int BlinkPeriod) {
  static unsigned long MyBlinkTimer;
  pinMode(IO_Pin, OUTPUT);
  
  if ( TimePeriodIsOver(MyBlinkTimer,BlinkPeriod) ) {
    digitalWrite(IO_Pin,!digitalRead(IO_Pin) ); 
  }
}


void recvMsg(uint8_t *data, size_t len){
  String d = "";
  for(int i = 0; i < len; i++){
    d += char(data[i]);
  }
  WebSerial.printf("Received Data: %s\n", d.c_str());
}

void setup() {
  Serial.begin(115200);
  delay(200);
  Serial.println("Setup-Start");
  PrintFileNameDateTime();
  WiFi.mode(WIFI_STA);
  Serial.print("Trying to connect to #");
  Serial.print(ssid);
  Serial.print("#");
  WiFi.begin(ssid, password);
  
  if (WiFi.waitForConnectResult() != WL_CONNECTED) {
      Serial.printf("WiFi Connection Failed!\n");
      return;
  }
  
  Serial.print("IP Address: ");
  Serial.println(WiFi.localIP() );

  /* WebSerial is accessible at "<IP Address>/webserial" in browser */
  Serial.print("WebSerial is accessible at ");
  Serial.print(WiFi.localIP() );
  Serial.println("/webserial in browser");  
  WebSerial.begin(&MyAsyncWebServer);
  
  /* Attach Message Callback */
  WebSerial.msgCallback(recvMsg);

  /* Start Webserver */
  MyAsyncWebServer.begin();
  delay(1000);
  WebPrintFileNameDateTime();
}

void loop() {
  BlinkHeartBeatLED(OnBoard_LED,100);

  if ( TimePeriodIsOver(MyTestTimer,2000) ) {
    MyCounter++;
    WebSerial.print("Here is your ESP. I'm counting up ");
    WebSerial.println(MyCounter);

    // at count 10, 20, 30 ... print Sourcode-Info
    if (MyCounter % 10 == 0) {
      WebPrintFileNameDateTime();
    }
  }  
}

Of course I did googling with keywords and found this interesting posting

User maxgerhard posted a lot of interesting links in his answer to this question

best regards Stefan

this is what my TelnetStream library does

2 Likes

I see a lot of half intelligent answers and suggestions, but this is easily the smartest way to handle serial ‘command line’ style of operation over a network.

It happily handled 115200 across the internet with a telnet client like PuTTY.
Use same print and parse routines - it just works.

I wrote my own telnet functions (not the above library) - it’s that easy once you get started.

Good luck… it opens up a huge opportunity, and is rarely mentioned!

1 Like

Would you mind sharing a demo-code?

I haven’t seen sed it for a while, I’ll have to dig deep.

Ran it on M2560 and 1284 projects.

I’ll dig around deep overnight.