1. Home
  2. Docs
  3. Documentation
  4. Quick Start
  5. Arduino

Arduino

Program for arduino

Before You start I suggest to take a look for creteaing webPage Quick Start

We connect our arduino (Wemos, nodeMCU or any arduino having a module to connect to the wifi network).

Before uploading, we have to upload the necessary libraries

(you can see on the movie how to do it)

 

  • WebSockets by Markus Sattler
  • ArduinoHttpClient by Arduino
  • ESP8266WiFi by Iven Grokhotkov
  • RemoteMe libraries by Remoteme.org

And then, let’s open the example of simpleArduinoMessage (File -> Examples -> RemoteMe -> simpleArduinoMessage )

before upload the example for arduino, we must complete the following:

  • WIFI_NAME – the name of our network
  • WIFI_PASSWORD – password to our network
  • DEVICE_ID – the id of our device
  • DEVICE_NAME – the name of our device – visible in RemoteMe in the device manager
  • TOKEN – token to our account in RemoteMe – go to the tokens tab and paste to arduino.ino our token

after completing the data, we upload the arduino program. Arduino after uploading and launching will register in our system.

for communication with RemoteMe.org, we use a RemoteMe object

then we set up two-way communication – this means that our Arduino connects to the RemoteMe and maintains an open connection with it, thanks to it we can both receive information from arduino and send

 

we set the function to be called the function in the example looks as follows:

in this case, it writes the received message to the serial port consoles

After calling these functions, our arduino will register in the RemoteMe.org system:

  1. Device type – arduino
  2. Connection status – at this moment the device is connected
  3. DeviceId
  4. Device name

Now send a message to our arduino, let’s open the example page

after clicking the Send to Arduino button, the numbers sent will be displayed on the serial port console.

Let’s check the javascript code that sends the message:

we can change our function

and then an array of bytes 1,2,3,4 will be sent to arduino

The most important function is:

in the index.html file we have a constant defined:

#### arduinoDeviceId # in display time will be replaced with our arduinoDeviceId, in our case it will be 205. Instead of using #### arduinoDeviceId# we can simply index.html:

operation will be the same.

the sendUserMessageByFasterChannel function sends a message to our arduino using the fastest available connection in our case it is a direct connection to arduino – arduino creates a websocket server:

and javascript connects to it:

when connected, the Direct webSocket button is green because:

 

We can click on “Direct websocket” – it will change color to gray then connection  browser – arduino will be closed, and the message will first be sent to RemoteMe.org, and then the system will send them to arduino – therefore the delay in shipment will be higher. Of course, when we open our site from the mobile phone using mobile internet, the “Direct websocket” button will be inactive because we do not have access to the internal IP of the device from the external network

 

I encourage you to read the example of flashing LEDs 🙂 to see more advanced sending of messages arduino <-> browser