How to access the local machine's serial port data using a Heroku application - ruby-on-rails

I have an existing Ruby on Rails Heroku application. I want to get the serial port data from the COM 1 port in a Windows computer using this application, but since Heroku is a cloud-based platform running on a Linux server, I am unable to get serial port data from the local machine where the Heroku application is running. If I run the standalone Ruby code on that Windows machine, then it works fine and I am able to get my desired data.
I am getting the following error
Unable to open COM1
How do I solve this issue?
The part of code of my Rails application through which I am accessing serial port data is:
port_str = 'COM1' #may be different for you
baud_rate = 2400
data_bits = 8
stop_bits = 1
parity = SerialPort::NONE
sp = SerialPort.new(port_str, baud_rate, data_bits, stop_bits, parity)
i=sp.gets.chomp
puts i
This code is working fine if I run it on that local machine. 'serialport' gem is there on my gemfile.

Rails is a web server technology that runs on a web server. It builds HTML pages that get sent to a client computer and are rendered by the browser.
When you run Rails locally you are mimicing a real web server - localhost is basically running a web server on your local machine. That is why you can cheat and use Ruby code in your Rails app that locally can access the port of your local machine, but once you run your Rails app on a real web server (like in Heroku) you cannot do this, so you have the wrong tool for the job you are trying to do.
Not only that but since Rails is a web technology you have a web application that runs inside the browser and you cannot easily access the port on a client machine from a web browser. More information on that is in "How to read serial port data from JavaScript".
The ONLY reason your Ruby code is able to access the port is because it is not running in the browser when you run on localhost but it is running inside the web server that gets fired up on localhost, so when the app runs on a real web server that Ruby code will try to access the port of the server not any client machine.

Related

Unable to run a application in localhost:8080

I am running a rails application in AWS cloud9 DEV env, listening on tcp://0.0.0.0:8080. i am able to open app on aws provided url (i.e https://xxxx.xxx.cloud9.us-east-1.amazonaws.com) but unable to open using localhost:8080.
I tried using protocol- tcp, http, https to run localhost:8080, also removed windows firewall defender. but did not work.
When i run the app using localhost, it says this site cant be reached.
The application hosted on the Cloud9 server, is running on a remote machine, not your local one. Localhost, and 127.0.0.1, correspond to your local machine, which I assume is not running this application. Should you run this application on your computer, you should be able to connect to it using localhost.
Moreover, if you are inside that Cloud9 machine, and you connect to it using localhost, you should be able to connect to it.
However, if you are connecting to it from a remote machine (i.e., you local device), you must connect to it using https://xxxx.xxx.cloud9.us-east-1.amazonaws.com

run rails app with an ubuntu server with global ip

Currently, we are running our rails app, on AWS but we tried to move it to Heroku, which didn't work at all, now We are trying to run the app on Virtual Machine on hetzner. I can run the app on local server easily, my question is that, How can we run our rails app with a specific IP and then we can access that app anywhere in the world from that ip? is that possible to do so? We are using PUMA for server.
Yes, you can access to to your site with specific IP.
In description of hetzner Virtual Server says that server have 1 specific IP. So than you deployed and run you application y can access to app with 1.1.1.1:80 or another port.
If i understand you. Also what happened with heroku?

Hosting Rails on local network

I have been deploying my rails app to digitalocean on ubuntu OS and it's working fine. However, I would like to deploy my rails app on a local ubuntu network.
I have tried to setup rails on ubuntu and it's working fine and I am able to open network access with port 3000 by the same network to access via
$ rails server -b 0.0.0.0
This a bit slow from another local network computer to access. What is the better way where I can deploy rails app to my local server and only for same local network usage.
I have been doing the same thing on a Raspberry pi with several projects.
You can actually treat your local server like an external one. You can deploy on the local server using capistrano.
Just make sure that your app on your local server will be deployed as production, not development. I would also recommend NGINX and unicorn for performance and zero downtime deployment.

Virtualbox rails server only accessible externally for some applications

I have an xUbuntu(14.04) virtualBox(4.3.15) server running on Windows 7. I have a 2 sites on the server and when I run rails server for either application it can be accessed internally at localhost:3000 without issue. However, when I access one app externally from a browser on the windows machine at the [virtualbox ip]:3000 the site renders without issue and the other displays 'cannot connect'. Additionally I can ping [virtualbox ip]:3000 for the one site, but the other will receive no response. Just the [virtualbox ip] can be pinged successfully when either site has rails server running.
Both sites are Rails 4.2.0.rc2, Ruby 2.0.0, and WEBrick 1.3.1.
Is there something that needs to be setup specifically so that the 2nd site works?
Haven't been able to locate any differences between the two which might cause an issue.
Was able to determine what the issue was. The one app was starting on http://0.0.0.0:3000 which to my understanding means it is listening on all interfaces, while the other app was starting on http://localhost:3000. The localhost app was therefore not listening for external requests. The solution was to start the rails server with the following.
rails server -b 0.0.0.0
This binds the app to the 0.0.0.0 ip address and I can now access it outside of my virtualbox xUbuntu instance by using [vm ip address]:3000 as the url.

Running Ruby on Rails app on server

I am using Aptana Studio 3 for development of ROR apps. I used run server command and it showed you can access your app on {http//0.0.0.0:3000/}, but when I try to access this URL, it tells me to check your Internet connection. I tried several other ports also but it is not working. I have created/modified the files necessary and migrated the database successfully too. Appreciate any help in running the app over the browser. I am currently using WeBrick Server.
so, in your title you say "on server". what does that mean? when you are running it on a different machine than your own, you need to use the address of that machine or it's domain name. keep in mind that firewall rules might prevent any connection to that server.
when you are ON the machine, via ssh for example, you can try calling the then "local" rails instance with curl http://localhost:3000/ to verify that it is running.

Resources