Elvas Tower: Use arduino via webserver - is it possible? - Elvas Tower

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Use arduino via webserver - is it possible? Rate Topic: -----

#1 User is offline   Alessio 

  • Apprentice
  • Group: Status: Switchman
  • Posts: 9
  • Joined: 09-March 21
  • Gender:Male
  • Simulator:Open Rails
  • Country:

Posted 24 April 2022 - 08:56 AM

Hi guys, I'm glad to meet you.
I am Alessio, a seventeen year old boy from Italy :)
In Italy our trains are equipped with a system that detects door lock (called "IPA" = open doors indicator), if one or more doors are open, a warning light turns on in cab.
I was wondering if it was possible, through the use of the webserver, to reproduce the lighting of a led connected to an arduino or similar microcontrollers after pressing Q (opening doors command).

I dont't know how to send data from OR to a ESP32 microcontroller that it's connected to a LED

I'm connected to the webserver using port 2150, and I noticed that from there you can see the status of the doors (closed or open) in some screen (e.g. the "Head Up Display (Alt+F5)").
After pressing alt+F5 in OR, while doors are open, a message appears in OR and in the webserver (watch the attached screenshot).
I took a look but I didn't understand much about the scripts and how OR send to webserver the data about the status of doors.

Can someone help me? :)
thank you :))

Attached thumbnail(s)

  • Attached Image: Screenshot (128)_LI.jpg

This post has been edited by Alessio: 24 April 2022 - 09:01 AM


#2 User is offline   Alessio 

  • Apprentice
  • Group: Status: Switchman
  • Posts: 9
  • Joined: 09-March 21
  • Gender:Male
  • Simulator:Open Rails
  • Country:

Posted 24 April 2022 - 10:24 AM

Ok thanks, I'll wait here :)
my goal is to send data to an external device and I think it can be done through Webserver-OR communication

#3 User is offline   cjakeman 

  • Vice President
  • PipPipPipPipPipPipPipPip
  • Group: ET Admin
  • Posts: 2,880
  • Joined: 03-May 11
  • Gender:Male
  • Location:Peterborough, UK
  • Simulator:Open Rails
  • Country:

Posted 24 April 2022 - 10:42 AM

Hi Alessio,


View PostAlessio, on 24 April 2022 - 08:56 AM, said:

I was wondering if it was possible, through the use of the webserver, to reproduce the lighting of a led connected to an arduino or similar microcontrollers after pressing Q (opening doors command).

I don't know how to send data from OR to a ESP32 microcontroller that it's connected to a LED

I see that the ESP32 is similar to the Raspberry Pi and supports programming in C, C++ and MicroPython.

If I were tackling this project, I would use the CabControls API as it's much simpler than the HUD API.

I would write a program in Python to execute on the ESP32 which requested all the data from the /API/CABCONTROLS/ that the webpage requests and then filter out all the values that you are not interested in. Use the Doors Open value to drive your LED.

You can perhaps see in the Content/Web/HUD/index.html that data is fetched from the webserver every 500 msecs, so as not to overload the simulation with requests for data. Your Python program should be restricted in the same way.

Hope that helps,

#4 User is offline   Alessio 

  • Apprentice
  • Group: Status: Switchman
  • Posts: 9
  • Joined: 09-March 21
  • Gender:Male
  • Simulator:Open Rails
  • Country:

Posted 24 April 2022 - 11:53 AM

Thanks for support!
Yes ESP32 is very similar to raspberry pi.

I am not familiar with programming in python at all so I don't know where to start...
after requesting all the data from the / API / CABCONTROLS /, where can I see the open doors variable?

#5 User is offline   pwillard 

  • Foreman Of Engines
  • Group: Status: Contributing Member
  • Posts: 808
  • Joined: 03-March 08
  • Gender:Male
  • Location:Cumming, Ga
  • Simulator:OpenRails
  • Country:

Posted 26 April 2022 - 06:21 AM

View PostAlessio, on 24 April 2022 - 11:53 AM, said:


Yes ESP32 is very similar to raspberry pi.



I feel that I need to disagree with this comment... the ESP32 is a Dedicated Microcontroller while the RaspberryPi runs a Linux operating system. It would be MUCH more straightforward to use a Raspberry Pi to create API calls than to use an ESP32. A solution to light an LED using an existing API would require the ability to interpret responses correctly. You *can* get an ESP32 to use a Python interpreter with MicroPython but for a newcomer, this can become a bit of a rathole.

I would recommend using a $10 PizeroW (if you can find one) for development and proof of concept before trying to do this with an ESP32.

Pete






#6 User is offline   Alessio 

  • Apprentice
  • Group: Status: Switchman
  • Posts: 9
  • Joined: 09-March 21
  • Gender:Male
  • Simulator:Open Rails
  • Country:

Posted 26 April 2022 - 06:57 AM

hi :)
My original idea was to edit the existing script (CabControls API) by adding the lighting of the led when "open doors" condition occurs after pressing Q.
I thought it could be done without doing a new program in python...
i thought about ESP32 because i'm using it for a similar school project, i've never used raspberry
so unluckily I am not able to make a new program in python because I've never studied it and i don't know where to start, I think it will remain an unfinished project unless there is someone who wants to help me by explaining how to do it.
i hope :)

Alessio

#7 User is offline   pwillard 

  • Foreman Of Engines
  • Group: Status: Contributing Member
  • Posts: 808
  • Joined: 03-March 08
  • Gender:Male
  • Location:Cumming, Ga
  • Simulator:OpenRails
  • Country:

Posted 26 April 2022 - 07:03 AM

View PostAlessio, on 26 April 2022 - 06:57 AM, said:

hi :)
My original idea was to edit the existing script (CabControls API) by adding the lighting of the led when "open doors" condition occurs after pressing Q.
I thought it could be done without doing a new program in python...
i thought about ESP32 because i'm using it for a similar school project, i've never used raspberry
so unluckily I am not able to make a new program in python because I've never studied it and i don't know where to start, I think it will remain an unfinished project unless there is someone who wants to help me by explaining how to do it.
i hope :)

Alessio


Well, it's not impossible... it is just the harder solution.

You need to be able to formulate the API call and PARSE the api response correctly. The example below assumes that you are using Arduino C++ Dialect.



example--->

A linux board with a full python implementation can natively process JSON style API calls without much effort


A handy tool for API testing is: "https://install.advancedrestclient.com/install" My link

#8 User is offline   Alessio 

  • Apprentice
  • Group: Status: Switchman
  • Posts: 9
  • Joined: 09-March 21
  • Gender:Male
  • Simulator:Open Rails
  • Country:

Posted 26 April 2022 - 10:55 AM

oh ok thanks I'll check it out as soon as I have some free time :)

I was thinking, instead of acting via webserver, would it be possible to turn on the led by connecting an arduino or similar via USB to the PC like with RailDriver?

is it possible to send data via USB from OR to arduino while OR is running?

I don't know if it can be done, I'm just trying to give some ideas, maybe it will help

#9 User is offline   Howky 

  • Fireman
  • Group: Status: Active Member
  • Posts: 247
  • Joined: 14-February 13
  • Gender:Male
  • Location:Czech Republic
  • Simulator:Open Rails
  • Country:

Posted 02 May 2022 - 10:21 AM

yes it is possible :) we use a program that reads data from the IP address of the webserver and sends it to the COM port, which is read by the arduino.
In the program we set the data we want to send.

To show the video:
https://www.youtube....vNmiGx35-8&t=4s

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users