Articles Hierarchy

Articles Home » Arduino Projects » ESP & Arduino

ESP & Arduino

What is the idea?
+ + (-4) need ESP32 tools for RPI linux Arduino IDE
+ + (1) MQTT for historic data collection
+ + (2) use Arduino board (ADC) via serial link
-5 restart win 7 PC new IDE
-4 and on RPI
-3 new brownout problem
-2 WEBSERVER for ESP32
-1 PID (uPCS) for ESP
-0 some old open points: INDx Face Plates, DCD point, SPIFFS
1 MQTT
2 linked UNO I/O


use ESP & Arduino not ESP vs Arduino


again, if i work RPI or if i play ESP ( like here and here), the features are impressing,
but i miss the GPIO 5V world AND the Analog In. ( but possibly should recheck on ESP32 Analog I/O Quality )

as the ESP mostly got famous as WIFI dongle for Arduino ( serial port, AT commands )
what i actually never tried, it took some time to get that actually the ESP is (could be) the workhorse.

MQTT for historic data collection


recently i play MQTT ESP8266 OLED ( to PRI MQTT broker Python service to sqlite3 database )
and RPI as webserver ( Flask ... Python )
now i want try to use that too on/from a ESP32 ( MQTT to RPI Broker ) ?problem?
but using real measuring data from a Arduino board.
If the ESP is just the

  • relay point for data to MQTTbroker ( and connected historic data sampling by python mqtt to sqlite3 )

  • or even run a application on the data ( like PID control )

  • and has its own webserver ( operator view/change ) like here

does not matter,
point is:
Arduino and ESP are the data collectors / controllers
but never used for historic data collection,
unless you have a very standalone application and upgrade with uSD Card like here
here the MQTT could be perfect to send regularly PID: PV/SP/OVP/Mode or even event driven Alarming/Status for recording.


need ESP32 tools for RPI linux Arduino IDE


also in my first tests with the ESP32 i got stuck using it from Arduino IDE via RPI Linux, now also want try that again see here and here


use Arduino board (ADC) via serial link


For the connection Arduino ESP i do not want to use the default serial because i will have connected USB to both boards, using IDE ( and monitor for diag prints )
so i will start with something like this, using softserial on pin 7/8 on both sides.
but i now read that actually ESP32 has 3 "hard serial" ( with free configurable pins )


and using for the (ESP) 3v3 / (Arduino) 5v problem a voltage divider like i see here

or use a add "breakout" board with this level shifter mos-fets, if i get it in time online.
as Rx Tx are strict one way easy, more see here;
the I2C.. as 2 way requires more ( and has a different HIGH definition of 0.7*Vcc =V5= 3.5V) see here
there is a whole world of solutions out there also with specialized ICs.. google it

i never see the idea to use 2 diodes in serial to reduce the voltage from 5 to ?3.6? but there
are many resistor diode examples, for pullup, limit with z-diodes...

also there is a upper range like with opto coupled ( potential free ) systems, what could be used for "measure at HIGH side"...

that's the idea:

note: the 2 pictures are for understanding, but you can have both at the same time ( or use "for Operation" extra 5V power ( for WIFI distance ))


enough said:

-5 restart win 7 PC new IDE


existing:
+ + Arduno IDE 1.8.5
+ + GIT update from here
try get Git-2.17.1.2-32-bit.exe /stuck at end of download ( must be the new microsoft version already ) try again 38.7MB.
put the https://github.com/espressif/arduino-esp32.git
at /hardware/espressif/esp32 ( sorry i do at IDE not at sketchbook but does not matter )
use windows explorer to start the git bash at /hardware/espressif/esp32/ ( open by context menu) and run
git submodule update --init --recursive
what not show me anything.
use windows explorer to start at /hardware/espressif/esp32/tools the
get.exe ( get " application" double click)




the mkspiffs subdir is new to me.


while the last public version in ESP_control_PID-master.zip is esp_control_RPI_v13 from 30.8.2017
my sketchbook goes up to
esp_control_v15d from 20.9.2017 but using ESP8266 ?where i got stuck with temperature sensor?
and stopped working ( see also ESP / 8266 / 32 as WIFI Arduino, while the ESP32 is actually loaded with a old v1.3
compiling 1.5d for ESP32 on PC failed.
compile and upload v1.3 worked but the ESP32 looped booting with msg in serial monitor
"brown out detected"

same with simplewifiserver example,
but when i connect ESP32 to a extra PSU the webserver worked
( but i miss the serial prints to arduino ide monitor )

what a difficult restart, so i am far away from my prior status, but i confirmed that the new PC Arduino IDE and the old ESP32 board are operational.


-4 and on RPI


ok, try ( again ) on a updated Raspberry Pi,
DEBIAN stretch
Linux version 4.14.34-v7+
Raspberry Pi 3 Model B Rev 1.2

and setup Arduino IDE like this


for ESP32 following this
sudo apt-get install gcc git wget make libncurses-dev flex bison gperf python python-serial

wget https://dl.espressif.com/dl/xtensa-esp32-elf-linux32-1.22.0-80-g6c4433a-5.2.0.tar.gz
mkdir -p ~/esp
cd ~/esp
tar -xzf ~/xtensa-esp32-elf-linux32-1.22.0-80-g6c4433a-5.2.0.tar.gz

nano .profile ( add at end )
export PATH="$PATH:$HOME/esp/xtensa-esp32-elf/bin"

check after reboot:
pi@RPI3:~ $ printenv PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games:/home/pi/esp/xtensa-esp32-elf/bin

follow this
cd ~/esp
git clone --recursive https://github.com/espressif/esp-idf.git
cd ~/esp/esp-idf
git submodule update --init
( here i stop because i think that is somehow wrong ( and not for raspberry pi and arduino IDE )


again see here
arduino-nightly/hardware $ mkdir -p espressif
cd espressif
git clone https://github.com/espressif/arduino-esp32.git esp32
cd esp32
git submodule update --init --recursive
cd tools
python2 get.py
(reboot) and start Arduino IDE
find ESP32 boards, select simpleWIFIexample again and try compile:



or compile it all?
sudo apt-get install gawk gperf grep gettext automake bison flex texinfo help2man libtool libtool-bin git wget make libncurses-dev python python-serial python-dev python-pip
sudo pip install pyserial
cd ~/esp
git clone -b xtensa-1.22.x https://github.com/espressif/crosstool-NG.git
cd crosstool-NG
./bootstrap && ./configure --enable-local && make install
./ct-ng xtensa-esp32-elf
nano ./.config #-- > Find CT_PARALLEL_JOBS=0 and change 0 to 1
./ct-ng build build.1 # start 10:23 ?auto restart 14:39 end 18:37
chmod -R u+w builds/xtensa-esp32-elf


so i see at 14:39 a auto restart of the build process?

end at 18:37 / about 8.2hours GRRRR.

#_________________________________________
if you read all the comments here and here looks that the
./ct-ng build build.1 should be just
./ct-ng build to avoid a double run.

ok, to get it run i try first copy:
~/esp/crosstool-NG/.build/xtensa-esp32-elf/builtools/
/bin
/include
/lib
/libexec
/share
/xtensa-esp32-elf
to:
~/esp/xtensa-esp32-elf/

but still compile error
/home/pi/Downloads/arduino-nightly/hardware/espressif/esp32/tools/xtensa-esp32-elf/bin/xtensa-esp32-elf-g++: no such file or directory
move it again ( now into arduino IDE )
change the .profile change back and reboot and restart IDE
but still same error, right, there is no g++ file:


for a test i go here and download xtensa-toolchain-rpi.zip 77MB
and that content look completely different
copy that into Arduino IDE and now:
got a permission denied, try make it executable then got error
xtensa-esp32-elf-g++: error trying to exec 'cc1plus': execvp: No such file or directory
#_________________________________________________
later i found i did copy from wrong dir: NOT /.build use /builds
so delete the downloaded thing and used the fresh compiled, but from the /builds directory
NOW compile and upload works:




-3 new brownout problem


BUT monitor also show brown out reboot looping


i need the serial monitor, my coding style requires one code line , one print line and
disable that diagprints later / or make it switchable by serial menu /
so digging how to disable that brownout thing:
here find:
#include "soc/soc.h"
#include "soc/rtc_cntl_reg.h"
void setup(){
WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 0); //disable brownout detector

here i see
CONFIG_BROWNOUT_DET
CONFIG_BROWNOUT_DET_LVL_SEL
CONFIG_BROWNOUT_DET_LVL
:

BROWNOUT_DET_LVL_SEL_0
BROWNOUT_DET_LVL_SEL_1
BROWNOUT_DET_LVL_SEL_2
BROWNOUT_DET_LVL_SEL_3
BROWNOUT_DET_LVL_SEL_4
BROWNOUT_DET_LVL_SEL_5
BROWNOUT_DET_LVL_SEL_6
BROWNOUT_DET_LVL_SEL_7

i try the change of the sketch first on PC,
could upload, see in monitor unreadable chars scrolling forever
could find the webserver when i used a extra PSU
but no way to find that port on PC (com25) again...
but from RPI i could upload old and new sketch again
and there even see the serial monitor:

so looks like i could start working again.
! pls. understand, this board did work one year ago very good from PC
with old Arduino IDE and old esp32 tools. ( but not from RPI at that time )


i do have now a RPI3B+ but thinking it is a different cpu from this RPI3B,
i should copy over to it for test / or build on it again? ( LATER )


-2 WEBSERVER for ESP32


while i checked on ESP32 news i see that the WEBSERVER
is still a open point, besides the basic one i learned a year ago that it is better to use ESP8266
code for this, but sorry i forget to document that one. But digging on dev status found recommendation for this but possibly its this
what i not see in BOTH is, HOW TO USE IT?
what i try first is to ( download ZIP ) and unzip/copy it to
...arduino-1.8.5\hardware\espressif\esp32\libraries\WebServer_tng-master
let's see if it conflicts with existing libs. looks good, i could upload the advanced webserver example
from PC, but with many problems serial port and retries, and run it from extra PSU.

Now i try same from RPI. ( but already include the Disable_Brown_Out )


note: the browser:"esp32.local" ( see MDNS.begin ( "esp32" ) ) does work from linux RPI,
but not from my WIN7, so i install on PC BonjourPSSetup.exe from here and then it works!


also build in some setup features i used with some old projects: #switches like
* useAP ( instead of login to your router ) ( tested with mobile phone login )
* useFIXIP ( instead of getting a IP from your router )
( in both cases better see the detailed serial prints in the IDE monitor )
and tested / upload from RPI and run on a ESP8266 and ESP32 board,
here with ESP8266:

pls. try


-1 PID ( uPCS 2 ) for ESP


now i have to combine that with the ?latest? running version of my
* PID..
* WEB Server operation
for ESP 8266 AND 32
from project: "esp_control_RPI_v13" from 30.08.2017 ( what could only be a ESP8266 version )
and from project "esp_control_v15e" from 20.09.2017 ( from PC using ESP32 ) already use SPIFFS (and start with linked temp sensor...)

MAIN PAGE has links to
* INFO
* CONTROL

the uPCS I/O and Control consists of
PID1
IND1 .. 4
DCD1 ( in work )
where the 5 analog points run on a scheduler like PID1,IND1,PID1,IND2...
the timing you can change in the loop timer but might effect the "analog" PV input filter tuning

the first HTML of visualization and operation ( PID1: MODE // SP // OVP )
* CONTROL is a more text based page ( with SVG buttons ) and a other link
* DETAIL what is SVG based


but first i run into some problems,
the concept of operation and refresh worked badly, insofar as the refresh repeated the last operation, i not know what the correct HTML "GET" is, so i need to take out the auto refresh and made a button.
here i want to show some of the elements i use here for a operation from HTML:
in a HTML page "/uPCS" i have a button call "/uPCS/SPUP" ( step up setpoint )
as i use my own SVG buttons i do it with like:
//button-link, button-width, button-height, button-color, Text-height, Text-color, Text-text
s += (show_Button("/uPCS/SPUP",100,30,"CadetBlue",12,"Gold"," SP UP "));

in the wifi setup need:
server.on ( "/uPCS", handle_uPCS );
server.on ( "/uPCS/SPUP",HTTP_GET, uPCS_SPUP);
server.onNotFound ( handleNotFound );
server.begin();

void uPCS_SPUP() {
setPID1_SP(PID1_SP + pidSPd); // step up SP
handle_uPCS();
}

while "handle_uPCS()" builds up the page again, the browser operation line stays "/uPCS/SPUP"
so a manual or auto refresh would step up SP once more....
i see no other way as to refresh manually ( by button ) as call "/uPCS"
until i find a way to do it correctly inline.


with GOOGLE i found here in the LED
example a other way looks worth testing:
a: use form POST ( do not copy, i show <' instead < to disable HTML here )
"<' form action=\"/LED\" method=\"POST\"><'input type=\"submit\" value=\"Toggle LED\"><' /form>"
b; use POST
server.on("/LED", HTTP_POST, handleLED);
..
c: use redirect
void handleLED() { // If a POST request is made to URI /LED
digitalWrite(led,!digitalRead(led)); // Change the state of the LED
server.sendHeader("Location","/"); // Add a header to respond with a new location for the browser to go to the home page again
server.send(303); // Send it back to the browser with an HTTP status 303 (See Other) to redirect
}

but fighting some time with form POST input submit // image
i found this idea in answer 3
<'form action="/test-button" method="POST">
  <'button>
   <'svg>
    <'rect width="100" height="100" >
   <'/svg>
  <'/button>
<'/form>

only bad that i still have that white frame around my nice SVG buttons
but a style border: none; and background color like the HTML page helped.
here under ESP8266 and with PV SIM ON

so, now auto refresh and button operation not conflict any more.


while the PLC /or/ PCS controller only use point type and numbers
and for analog only work with 0.0 ... 100.00 "%" ( about 2.5 decimales correct with 12 bit resolution )
a PCS visualization must use point TAG // name // desc // EGU // low & high Range //
( and also the show for the historic trend need that )
here our PCS is more a nPCS "nano" as "micro" with a ESP8266 for 3.11 euro what includes the controller and the "visualization/operation" webserver.
so i will include that extended point config in the controller PID config,
not show it here in first page, but as needed for the DETAIL page Face Plates.


now try to get the SVG "Face Plate" thing running again.
for PID1 with slider operation (incl number input and [ENTER] OR "send' button) and
the 2 tuning lists in SVG form ( inline version )

the slider position inside the "table of 5" still ugly, need to find a way to center it.
<'table align=\"center\"> can do the trick? no, and inside the slider <'div align=\"center\" > also not.
so need 2 more table columns and some forced spaces...



for understanding the 2 tuning lists
// in a older revision that where SVG files at SPIFFS and i hope i can do that again for both ESP boards.

i not try to make the system online tunable, so change tuning will require a upload.
on the other side i not yet make that parameters "const"
and if you never worked with PID loops on PCS that looks like lots of parameter. YES

but for tune the PID / gain / reset / rate / you actually need help,
means testtool to change that parameters online AND a Current Trend Tool to show the results.
both could try with MQTT to/on RPI instead of try it here in HTML on ESP ??


as this looked like a good status try on ESP32 and run into continuously rebooting with
Guru Meditation Error: Core 0 panic'ed (IllegalInstruction)
. Exception was unhandled.


try with disable PID
//#define usePID // or disable with //
but still same, but webserver was running
info page worked, BLUE LED operation too,
and serial print after RESET Button press ok??
retry with PID now works? a glitch?
pls. try


0 some old open points: INDx Face Plates, DCD point, SPIFFS


as much i want start with this project ( like with MQTT and link to UNO I/O )
this code is not ready,
on the other side both boards already react like unstable, so filling them more up
even before i start the real project work also not feels good.
worst case i need to DISABLE WebServer to ENABLE MQTT, that would be OK, will see.


i was able to make the SVG for IND faceplate and IND tuning as functions,
so i just call them 4 times with the changed variables IND1 .. IND4

but i noticed one possible mistake, the tuning / understanding for the alarm limits is what? % or EGU
usually its PCT in PCU (Process Control Unit) and compared with PV %
and generate one point alarm NUMBER ( highest priority ) what is reported
and later translated at a DCU to a alarm msg text (list),
and further processed for interlocking...
and in DCU (Display Control Unit)
i do show the alarm settings ( in PCT )
if i would allow tuning from that window i would need to translate to EGU and the tuned value back to PCT.


the DCD point is prepared, but not much use to show in HTML now, as PV and SP of a DVD are integer numbers and
must be translated to text lists of actual PV words ( ON OFF FAIL ...)
and SP words ( START STOP ... )
actually that thing could be so big that it should be a separate project.


SPIFFS
i had that running for ESP8266, a 1MB filesystem what was used to serve image files via the Webserver. will see if that code runs on both boards.
well as usually, i am not lucky.
to get it compiled for ESP32 i needed first
#ifdef useSPIFFS
#include <'FS.h>  // use SPIFFS see tab Spiffs
#include <'SPIFFS.h>
#endif

and i neded to replace my old code regarding reading that spiffs dir, pls. see here
but still:
______________________
my_ESP_WebServer_PID
V2.3 on ESP32
_____________________

E (10210) SPIFFS: mount failed, -10025
SPIFFS Mount failed
file open failed
file open failed
Listing directory: /
- failed to open directory

a test using "FS.h" instead <'FS.h> same.
-a- the old way to have a
/data/img/ dir in the arduino sketch does not work ( for ESP32 ) // like to be uploaded
and / or
-b- that new dir code does not work anyhow.
using the library SPIFFS-test example same bad, so it must be the board,
testing as "NodeMCU-32S" and "Node32S" same.


back on board ESP8266
use old setup and file generation at setup.. and original dir code
works nice
1384, room 16
tail 8
chksum 0x2d
csum 0x2d
v614f7c32
~ld
______________________
my_ESP_WebServer_PID
V2.3 on ESP8266
______________________

SPIFFS Mount succesfull
make: /img/tuninganalog.svg
make: /img/tuningPID.svg
SPIFFS content:
/img/tuninganalog.svg 3425
/img/tuningPID.svg 2114
SPIFFS total: 957314 used: 6275

MDNS responder started,use from browser: esp8266.local
STA Mode on kll-wlan_2.4G IP: 192.168.1.210
HTTP server started on Port 80
{'IND1':{'PV':10.09}}
{'PID1':{'PV':50.70,'SP':0.00,'OV':65.91,'MD':2.00}}
{'IND2':{'PV':20.26}}

but upload from /data/img/ dir
need more tools: here
see also my old blog here
after copy in the tool close/open IDE, select project with the /data/img/favicon.ico dir
and do the upload thing
even all looked good, the file (/img/favicon.ico) is not there.



well, my bad,
i have to repeat the upload of SPIFFS /data/
and change the sketch upoad option from erase flash to upload sketch and WIFI only
and change the header of all pages

as this not works for ESP32 until now, i have to do the semistatic pictures ( and the use of them ) for ESP8266 only.
#ifdef ESP8266
#ifdef useSPIFFS
s += ("<'img src=\"/img/tuninganalog.svg\" alt=\"tuning1\" >");
#else
s += (show_tuninganalogSVG());
#endif
#else //ESP32
s += (show_tuninganalogSVG());
#endif

but i do love my icon icon
making the semistatic for all tuning SVG at boot

pls. try


1 MQTT


my last play project was a ESP8266 board with OLED and i used it for test MQTT to RPI with SQlite3 DB... see here
so now the question is: can i get exactly that also running on ESP32.
now i not do a new setup so all should be ready? but better check for add libs ( updates ) for arduino IDE?
[sketch][include library][manage libraries][search "pubsubclient"] OK
i made a new TAB "MQTT" and could nearly all related code pack there,
and have following calls:
in Setup()
MQTT_setup(); // see TAB MQTT
in loop()
MQTT_loop(); // see TAB MQTT
in send() at "TIMER"
MQTT_trend(); // see TAB uPCS
MQTT_send();
in uPCS create the string ( if MQTT AND usePID )
mqtt_string="{\"PID1_PV\":"+String(PID1_PV)+",\"PID1_SP\":"+String(PID1_SP)+",\"PID1_OV\":"+String(PID1_OV)+",\"PID1_MD\":"+String(PID1_MD)+"}";
the boot and MQTT connect ( and send string ) worked directly ( every minute ),
as it is still same RPI setup used with MQTT broker installed.

now check if the data come there and can be recorded.


check com on RPI side first ( terminal level):
-a- make some alias
in .bash_aliases
# MQTT
alias MQTTsys='mosquitto_sub -v -t \$SYS/#'
alias MQTTshow='mosquitto_sub -h 127.0.0.1 -t "#" -v'
# LED on ESP
alias MQTT_LED_ON='mosquitto_pub -h 127.0.0.1 -t "pcu210/in" -m "1"'
alias MQTT_LED_OFF='mosquitto_pub -h 127.0.0.1 -t "pcu210/in" -m "0"'

show trending:
pi@RPI3:~/projects/myblog $ MQTTshow
pcu210/sensor/out {"PID1_PV":36.11,"PID1_SP":0.00,"PID1_OV":100.00,"PID1_MD":2.00}
pcu210/sensor/out {"PID1_PV":31.46,"PID1_SP":0.00,"PID1_OV":100.00,"PID1_MD":2.00}
pcu210/sensor/out {"PID1_PV":30.01,"PID1_SP":0.00,"PID1_OV":100.00,"PID1_MD":2.00}
pcu210/sensor/out {"PID1_PV":32.02,"PID1_SP":0.00,"PID1_OV":100.00,"PID1_MD":2.00}

and try operation
pi@RPI3:~ $
pi@RPI3:~ $
pi@RPI3:~ $ MQTT_LED_ON
pi@RPI3:~ $
pi@RPI3:~ $
pi@RPI3:~ $ MQTT_LED_OFF

all looks very good
there is also no problem to run a ESP8266 webserver page / autoupdate 15sec
and operate the PID, trending still works.
MQTTshow
pcu210/sensor/out {"PID1_PV":60.00,"PID1_SP":0.00,"PID1_OV":100.00,"PID1_MD":2.00}
pcu210/sensor/out {"PID1_PV":52.09,"PID1_SP":0.00,"PID1_OV":100.00,"PID1_MD":2.00}
pcu210/sensor/out {"PID1_PV":43.82,"PID1_SP":2.00,"PID1_OV":98.00,"PID1_MD":1.00}

oh oh, but when the MQTT can not connect it stays in that deadly reconnect loop
and webserver not work.


in this project i used my BLOG
a RPI python CMS setup
to deal with (remote) MQTT data recording and show via webserver, more here and i use the include file
mqtt_settings.py"""filename: mqtt_settings.py
"""

mqtt_broker="127.0.0.1"
mqtt_out="pcu213/sensor/out"
mqtt_in="pcu213/in"

# for DB see /static/data/
MQDATABASE = 'myMQTT.db'
DB_exists = False
TABLE_NAME = mqtt_out.replace("/","_") # SQL not take the mqtt topic structure
TB_exists = False

by change that to 210 and even a new database file it might work,
or change IP and topic of ESP ( more easy )
-a- for webserver on RPI
pi@RPI3:~/projects/myblog $ ./start
start python flask MYBLOG webserver, stop with [ctrl][c]
* Running on http://0.0.0.0:4567/ (Press CTRL+C to quit)
* Restarting with stat
* Debugger is active!
* Debugger pin code: 339-918-048

-b- for MQTT catch sensor data and store to database
pi@RPI3:~/projects/myblog $ ./start_mqttdb_service
start python mqtt ESP to MQTT database service, stop with [ctrl][c]
first run? not find db file static/data/myMQTT.db
time: 2018-07-06 08:55:17, topic: pcu213/sensor/out, messagestr: {"PID1_PV":69.23,"PID1_SP":0.00,"PID1_OV":100.00,"PID1_MD":2.00}

-c- my BLOG in browser ( and login )

and also the operation of the LED works, but inverted ( too many inverts on the way )
good,
so for ESP8266 i got the uPCS and webserver operation
and the MQTT datacollection to RPI running,
also show historic data in my_BLOG webserver ( on RPI )

( from PC browser to ...203 RPI (myBLOG) and ...213 ESP8266 (ESP uPCS) )
i am happy but that was just the combination of 2 existing play projects.
the real point was to get that runnning for ESP32 too.


lets try to load that on ESP32
-a- RPI IDE change board settings
-b- disable SPIFFS
-c- compile (OK)
-d- upload (OK)
-e- check ser monitor for MQTT connect (OK)
-f- RPI my_BLOG save MQTT data ./start_mqttdb_service
-g- RPI my_BLOG webserver ./start
-h- PC browser ...213 ESP32 uPCS operate mode output setpoint
-i- PC browser ...203 RPI my BLOG / login / MQTT


so that was a ( very rare easy AND ) big step for this project.



but not all is peachy in ESP wonderland!
- - OPEN POINT LIST
-a- when i play PID Mode and SP i think there is a code error regarding
MAN to AUTO, that should be "BUMPLESS" for OUTPUT.
looks more like first output jump to 100% then come back and follow integral ( but how to see without a fast "current trend" module)
-b- an hour earlier i changed the MQTT string to include the IND1..4_PVs, but it did not send
so i changed back. need to check very deep in all tools..
-c- all should work for multiple float values via MQTT, Database, Trend
what i remember was the color thing for the trend "bullets" i made manually for 4 only,
anyhow not have much control over that color and the list sequence PV SP OV MD..
so colors not fit to faceplate color: PV yellow, SP white, OV cyan is a old color definition.
-d- if MQTT server not connect, a reconnect try blocks all (solved)
-e- LED operation logic from myBLOG/MQTT ( but would need to change ESP8266+OLED project too )


now i am thinking to solve the tuning problem, i refuse to do all this code again like i did for RPI (python) uPCS where you can tune the UNO... / the end must be a upload with new tuning settings!!! anyhow /
but my idea is to make a extra MQTT tool what allow
+ + to setup a (fast) current trend and
+ + change the PID parameter for testing to find the good tuning parameters
( like here from the RPI what is also the MQTT broker )
-a- make a tunable bit to switch MQTT send
+ from send all 60 sec ( trending ) to send after PID1 loop run ( currently 5 sec )
+ operate that bit via MQTT
but now decode only "1xxx" and "0xxxx" as mqtt msg for LED ON OFF
-b- allow send "gain:0.0,reset:0.0,rate:0.0," via MQTT and change that variables for PID
( until reboot..)
both not need to be "in" ESP webserver or RPI websever
there just need to see the now faster "current" trend.
-c- operation from commandline RPI

-A-
erase the reconnect looping and

make the CT bit ( Current Trend switch from Historic Trend )
______________________
my_ESP_uPCS_MQTT
V2.5b on ESP32
______________________
..
MDNS responder started,use from browser: esp32.local
STA Mode on kll-wlan_2.4G IP: 192.168.1.213
HTTP server started on Port 80
{'IND1':{'PV':10.09}}
Attempting MQTT connection...connected as: kll/pcu213 usr: default and pwd
MQTT connected
{'PID1':{'PV':50.70,'SP':0.00,'OV':65.91,'MD':2.00}}
{"PID1_PV":50.70,"PID1_SP":0.00,"PID1_OV":65.91,"PID1_MD":2.00}_MQTT_send


-B- MQTT remote tuning operation use from RPI terminal like:
: enable fast trending :
mosquitto_pub -h 127.0.0.1 -t "pcu213/in" -m "T:{CT:1}"
: change a tuning :
mosquitto_pub -h 127.0.0.1 -t "pcu213/in" -m "T:{PID1_gain:0.15}"
pls note that that is NOT clean JSON, i not use {"T":{"PID1_gain":0.15}}
as i use here the ESP32 ( and not the ESP8266 + SPIFFS + with fix tuningSVG pictures ) i can see the result of the RPI manual MQTT remote tuning after latest 15sec in the ESP32 PID DETAIL webpage

in case of ESP8266 ( and SPIFFS enabled )
i need to (re)generate the semistatic tuning picture after each remote tuning (by MQTT) again.
TAB MQTT, detect "T" for TUNING else if ((char)payload[0] == 'T') { // remote tuning function
db(dbgMQTTd,"remote tuning: ");
// now take that appart, expecting only 1 set: {MQvar:MQval} and no "
String MQcommand = MQ_message.substring(MQ_message.indexOf('{')+1,MQ_message.indexOf('}'));
db(dbgMQTTd,MQcommand);
String MQvar = MQcommand.substring(0,MQcommand.indexOf(':'));
String MQval = MQcommand.substring(MQcommand.indexOf(':')+1);
float MQvalf = MQval.toFloat(); // need check for bad typing input
db(dbgMQTTd,", variable: "); db(dbgMQTTd,MQvar); db(dbgMQTTd," value: "); db(dbgMQTTd,MQvalf); dbln(dbgMQTTd,"");
if ( MQvar == "CT" ) {
if (MQval == "1" ) { CT = true; dbln(dbgMQTT,"current trend");} // MQTT reporting at PID1 timing 5sec
if (MQval == "0" ) { CT = false; dbln(dbgMQTT,"historic trend");} // MQTT reporting at LOOP timing 60sec
}
if ( MQvar == "PID1_gain" ) { setPID1_gain( MQvalf); dbln(dbgMQTT,"setPID1_gain"); reprint();}
if ( MQvar == "PID1_reset" ) { setPID1_reset(MQvalf); dbln(dbgMQTT,"setPID1_reset");reprint();}
if ( MQvar == "PID1_rate" ) { setPID1_rate( MQvalf); dbln(dbgMQTT,"setPID1_rate"); reprint();}
// use from RPI terminal like // mosquitto_pub -h 127.0.0.1 -t "pcu213/in" -m "T:{CT:1}" // mosquitto_pub -h 127.0.0.1 -t "pcu213/in" -m "T:{PID1_gain:0.15}"
client.publish(outTopic, "AKN T");
}


pls. try



2 serial linked UNO I/O


here i want use a old project about serial menu for UNO.. pls see here (10.6.2015)


besides this actual project setup pls. take your time and check about that thing,
it is not only a usb serial menu, also a multi tasking framework...
also used as basis for some of my other projects like PoorManScope and UNO uPCS.


Because for the INPUTS sending of 3 analog and 3 digital measurements to serial port (in ascii) is easy,
but if i also want do OUTPUTS like 3 PWM out and drive 3 digital output too i need lots of serial code. Now, all that i have in my serial menu ready,
only that that menu, where i can send OUTPUT SETpoints from ESP to Arduino UNO, need to run not on the USB / CONFIG port like now,
it must work on the (soft serial for UNO ) link to ESP.
-a- i work littlebit on the old code ( make a rev 2.9d with disable all RTC code so no add libs needed )
-b- make the rev 3.0 and start with following UNO I/O
+ + soft serial: rxPin 10 txPin 11 ( sofar i read that should work also on Leonardo and Mega )
+ + + the serial baudrate i will try sersbd = 115200
- - there are warnings about Softserial inflicts timer...
- - other ?older? manual say baud rate is limited... we will see

+ + Analog In: A0, A1, A2
+ + Digital In: D2 (+1), D4 (+2), D7 (+4), send as a integer "dig3" 0 .. 7
send as ,1023,0,0,7, ,A0,A1,A2,dig3, "CSV style" to both serial ports.

+ + Analog Out (PWM) D3, D5, D6,
+ + Digital Out D8, D9, D12
( + D13 is UNO ON BOARD LED see JOB 1 )

i used JOB 9 of the SERIAL USER MENU code with a timersetup of 2 sec.
with USB menu ( " " or "?" see option list )
9[enter] you switch JOB 9 OFF and with
9[enter][enter] switch ON again or
9[enter]5000[enter] switch ON with 5sec measuring loop timer ( only until reboot ( also at IDE ser. monitor close!!!))


The situation with 3 boards of different type and lots of I/O is getting difficult, so i try a external documentation here



in the old code are 2 tests prepared, the detection on input
NUMBERS ( negativ, int, real ) old menu point "r" and the splitting on CSV lines old menu point "C"
i changed that to our new menu point
"O" ( for Output )
so when we do
O[enter],255,255,255,7,[enter]
our new output is set.
here a picture with reduced debuging

but pls, that is only on the USB link up to now.
So we have a situation where a UNO board
( with that fix I/O definition 3 Ain, 3 Din, 3 Aoutpwm, 3 Dout )
is sending the readings of the inputs ( every 2 sec )
and accept that "remote" setpoints with the menu switch "O" and a CSV line ",255,255,255,7,".
so besides that i will use the softserial port for this later we have already a good product:
from PC and RPI that can be used as I/O for power and COM via USB.
means i will (later) write some example python code to use that Arduino UNO this way.
sure can not compete with FIRMATA, but that is the whole point here, the Arduino UNO can run FIRMATA ( as "slave") , but i not know how to use that via a softserial link to ESP and find a FIRMATA (as "master" ) for ESP.



the USB serial menu code consists of a
-a- counter ( from every loop ) with endcheck
-b- at that check for serial available
-c- take the first char and clean the rest ( b + c called "one char serial input no wait" )
-d- compare that character with the options from MENU list
-e- if "O" start a "serial read line with wait but timeout"
-f- check the ","s in that line and split to a variables array
-g- check the variables on integer number and valid range
-h- send that setpoints to the hardware outputs.

this 2 different ways to use the serial port
* one char input no wait
* one line wait and read with timeout
i needed to do again for Soft Serial.

to test that i first make a test code ( loaded on a Arduino Leonardo )
what works like a terminal program
* what the soft serial reads it prints to serial
* what serial reads it sends to soft serial

code
that test ( UNO / Leonardo crosswired 10 / 11 ) for code and baudrate
shows that the code works, the communication on the serial wiring not very good.
UNO , Leonardo
GND, GND
D10,D11
D11,D10
the GND wire connects a USB GND of a "earthed" PC with the floating PSU / RPI USB / UNO

so wiring AND serial baude rate in question.
test of softserial down from 115200 to 19200Bd not see errors.


a function test with a short wire
UNO I/O:
D12 to A1
and remote operation (at IDE serial monitor Leonardo )
O[enter],0,0,0,4,[enter]
O[enter],0,0,0,0,[enter]
works fine.



now work on hardware ( levelshifter )
found some old unpacked parts, one looks interesting,
but my Alzheimer is not helpful here, i think i order it because the MAX32 and the Arduino DUE are 3v3, ( that was long b4 using RPI.. ), found it with a also never tested arduino motor driver board from DF Robot.

i make it ready for soldering and shoot that photo with the tablet, so i can read something:

found some info adafruit and sunrom but not at cjmcu

more info at TI datasheet
still not sure that can be used for serial com.