Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

Sorry, you do not have permission to ask a question, You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please type your username.

Please type your E-Mail.

Please choose an appropriate title for the post.

Please choose the appropriate section so your post can be easily searched.

Please choose suitable Keywords Ex: post, video.

Browse

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Logo Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Logo

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Navigation

  • Home
  • About Us
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • About Us
  • Contact Us
Home/ Questions/Q 4500

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Latest Questions

Author
  • 61k
Author
Asked: November 27, 20242024-11-27T12:34:07+00:00 2024-11-27T12:34:07+00:00

Connecting Arduino to Internet using Websockets.

  • 61k

In this article I will be sharing a recent project that I made using arduino.

Few years back, I made several arduino projects that used wireless communication using IR sensors and bluetooth. Though they worked perfectly but the only limitation was that the communcation range was not very great.

I was always fascinated by controlling the microcontroller using internet, while researching I found that we need hardwares like Ethernet sheild, routers and static IP for client-server communication to make arduino webserver.

Recently, I learnt about websocket protocol and socket.io library, and thought to connect my arduino with the internet and control its sensors.

Since I had no ethernet sheild and router, it was impossible for me to establish direct communication between a browser and arduino. To resolve this issue, I decided to communicate with the arduino indirectly, ie via a remote server hosted on Render.com.
In this solution, the client will establish websocket connection with the remote server. At the same time my arduino which is connected to nodejs server on localhost sending data via serialport, will also establish websocket connection with that remote server.

The scenerio looks like this:

Image description

For websocket connection, I used one of the popular libarary called Socket.io. It is a great libary for making realtime projects, and it is very easy to use too.

Image description

Image description

In my project, browser and nodejs localhost server were clients and the remote server was the main socket server.

Since, I had established the realitime connection between the local machine and browser, I had to connect the arduino with the local machine so that it can control the sensors.
In arduino we have the access to write on serial port. ie Serial.println("turn on led"). We can access serial port in nodejs using a npm library called serialport. With that, our whole problem is solved. Let me explain:

We will send emit lightOn message from the browser, this message will be catched by the remote server, then it will forward this message to the local nodejs server (remember, this local nodejs server is already connected to the remote server, because it is client with respect to it, and it had already established the connection).
The local nodejs server will read the message, and accordingly write commands to the serial port. Since the arduino is already connected, it will read serial port and take necessary steps with the sensors. After performing tasks on the sensors, arduino will write acknowledgement signals to the serial port.
Since the local nodejs server is continuously reading the serial port, as soon as it gets the acknowledgement, it will emit socket packet to the remote server conforming that the command has been fullfilled. The remote server will in turn report to the browser about the fullfillment of the command and the brower will update its UI accordingly.

Below is the detailed diagram of the process involved in this process.

diagram link
Image description

arduinonodesoftwareengineeringwebdev
  • 0 0 Answers
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

Sidebar

Ask A Question

Stats

  • Questions 4k
  • Answers 0
  • Best Answers 0
  • Users 2k
  • Popular
  • Answers
  • Author

    Insights into Forms in Flask

    • 0 Answers
  • Author

    Kick Start Your Next Project With Holo Theme

    • 0 Answers
  • Author

    Refactoring for Efficiency: Tackling Performance Issues in Data-Heavy Pages

    • 0 Answers

Top Members

Samantha Carter

Samantha Carter

  • 0 Questions
  • 20 Points
Begginer
Ella Lewis

Ella Lewis

  • 0 Questions
  • 20 Points
Begginer
Isaac Anderson

Isaac Anderson

  • 0 Questions
  • 20 Points
Begginer

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help

Footer

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise

Querify Question Shop: Explore, ask, and connect. Join our vibrant Q&A community today!

About Us

  • About Us
  • Contact Us
  • All Users

Legal Stuff

  • Terms of Use
  • Privacy Policy
  • Cookie Policy

Help

  • Knowledge Base
  • Support

Follow

© 2022 Querify Question. All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.