I have a project idea where the device is not going to be located next to my computer. However, I would like to upload sketches OTA via wifi and monitor the device (Serial.print) OTA via wifi.
I have been successful in using the ArdunioOTA library to upload sketches OTA, but I am having issues with monitoring the device.
I am learning that the Serial Monitor doesnt work natively with WiFi connections. From my reading it seems the library TelnetStream can convert my Serial.print statements into something that my computer can read via wifi, but I am having trouble getting TelnetStream working. I can not follow the example sketches in the TelnetStream library. Does anyone have a tutorial of how to use the TelnetStream library?
sorry I am not familiar with the Nano ESP23, can you post a link to its technical information? Have you tried putty?
Can you identify which lines of code you do not understand?
0 #include <WiFiEspAT.h>
1 #include <TimeLib.h>
2 #include <TelnetStream.h>
3
4 const int8_t TIME_ZONE = 2; // UTC + 2
5
6 void setup() {
7 Serial.begin(115200);
8
9 Serial1.begin(115200);
10 WiFi.init(Serial1);
11
12 if (WiFi.status() == WL_NO_MODULE) {
13 Serial.println();
14 Serial.println("Communication with WiFi module failed!");
15 // don't continue
16 while (true);
17 }
18
19 // waiting for connection to Wifi network set with the SetupWiFiConnection sketch
20 Serial.println("Waiting for connection to WiFi");
21 while (WiFi.status() != WL_CONNECTED) {
22 delay(1000);
23 Serial.print('.');
24 }
25 Serial.println();
26
27 WiFi.sntp(TIME_ZONE, "us.pool.ntp.org");
28
29 Serial.println("Waiting for SNTP");
30 // while (!WiFi.getTime()) {
31 // delay(1000);
32 // Serial.print('.');
33 // }
34 setTime(WiFi.getTime());
35
36 IPAddress ip = WiFi.localIP();
37 Serial.println();
38 Serial.println("Connected to WiFi network.");
39 Serial.print("Connect with Telnet client to ");
40 Serial.println(ip);
41
42 TelnetStream.begin();
43 }
44
45 void loop() {
46
47 switch (TelnetStream.read()) {
48 case 'C':
49 TelnetStream.println("bye bye");
50 TelnetStream.flush();
51 TelnetStream.stop();
52 break;
53 }
54
55 static unsigned long next;
56 if (millis() - next > 5000) {
57 next = millis();
58 log();
59 }
60 }
61
62 void log() {
63 static int i = 0;
64
65 char timeStr[20];
66 sprintf(timeStr, "%02d-%02d-%02d %02d:%02d:%02d", year(), month(), day(), hour(), minute(), second());
67
68 TelnetStream.print(i++);
69 TelnetStream.print(" ");
70 TelnetStream.print(timeStr);
71 TelnetStream.print(" A0: ");
72 TelnetStream.println(analogRead(A0));
73 }
Follow the more info on the TelnetStream library for the little bit of documentation. It is fairly simple though.
I would test it but I can't compile the code for the NANO-ESP32, it fails on
fork/exec /bin/xtensa-esp32s3-elf-g++: no such file or directory
and I don;t know why.
If I try any of the other boards it should work on I get permissive errors so it may be the library is
I found another library, it is TelnetStream2. It uses WiFiMgr so that is address 192.168.4.1 but I have a router that blocks that so can't test. I also don;t see any docs. It is basically the same.