1. Home
  2. Sorce Documentation
  3. Libraries
  4. Arduino – Core functions

Arduino – Core functions

RemoteMe class

Configuring, monitor connection, sending messages, receiving messages.

 

 

sourceCode

Prepare
How import library

 

  • Install arduino library Sketch >> include library >> manage libraries by adding remoteme by remoteme.org

  • Then File -> Examples -> RemoteMe -> empty Sketch

  • Provide information about your WiFi, token and device itself

  • Add dependencies
    • WebSockets by Markus Sattler:

    • ArduinoHttpClient by Arduino

    • ESP8266WiFi by Ivan Grokhotkov (if You are using ESP8266 module)

  • Compile and upload project into the device
  • Your device will be automatically added at app.remoteme.org/#/app/devices
Functions
getInstance(token,deviceId)

Get instance of RemoteMe.class object. If no instance is created yet its creating instance based on token and deviceID. If instance is already created token and deviceID parameter are ignored. Object of RemoteMe should be placed as global variable.

Example of use:
 

setupTwoWayCommunication()

Setup socket (on port 18 – if by some reason ( for example firewall ) You cannot use this port instead of setupTwoWayCommunication function use setupTwoWayWebSocketCommunication ) communication, after call this function device at deviceTab will be link to RemoteMe application and will be ready to process incoming messages.

If the function setupTwoWayCommunication or  setupTwoWayWebSocketCommunication is not called, device will not get any messages, but still will be able to send messages ( by using standard send Message functions ( REST ), sending messages at this mode is much longer then by using WebSocket connection )

setupTwoWayWebSocketCommunication()

Works exactly like setupTwoWayCommunication but instead of socket communication on port 18 its connecting using webSocket protocol on standard 80 port. In most cases call setupTwoWayCommunication instead of setupTwoWayWebSocketCommunication

sendRegisterDeviceMessage(String deviceName)

Update device Name and type at RemoteMe system. This function is not mandatory if the device (recognized by deviceID ) already has set proper name and type.

setUserMessageListener(onUserMessage function)

Set function which will be call when user message will come to the device, check onUserMessage  at Events paragraph

setUserSyncMessageListener(onUserSyncMessage function)

Set function which will be call when user synchronized message will come to the device, check onUserSyncMessage at Events paragraph

sendUserMessage(destinationDeviceId, dataToSent, dataSize)

send User message to destinationDeviceId

parameters:

  • destinationDeviceId: uint16_t – where message will be send
  • dataToSent: uint8_t* – pointer to data to send
  • dataSize: uint16_t – dataToSent size

If websocket is opened message will be sent by websocket, otherwise using http post method (much slower)

sendUserMessage(destinationDeviceId,message)

send User message to destinationDeviceId

parameters:

  • destinationDeviceId: uint16_t – where message will be send
  • message: String – message to send

If websocket is opened message will be sent by websocket, otherwise using http post method (much slower)

sendAddDataMessage(seriesId,settings,time,value)

its sending value to store in RemteMe database. Each time function is called into RemoteMe database is saved <seriesId,value,time>.

parameters:

  • SeriesId – seriesId each series is saved in another table ( for example to store temperature from one place use always the same series ID number each time You want to save temperature data from that place).
  • settings – possible values :
Its use to round given time . For example when RemotemeStructures::_1M is used then function data series is written with time rounded to 1 minute.

  • time – specify with what time data should be save to the server, time is in milliseconds in Unix time. if 0 is passed then data series are saved with current data & time. This value before store in database are round based on settings  parameter
  • value – value to store represented by 8 bytes float number.
loop()

function checking if there are any data for the device, checks websocketConnection (if its configured), and reconnect if needed.

This function need to be called at main program loop

example of use:

Events
onUserMessage: function(senderDeviceId,dataSize,data)

function will be called when userMessage comes to script

example:

onUserSyncMessage(senderDeviceId, dataSize, data, &returnDataSize, *&returnData)

function will be called when userSyncMessage comes to script.

parameters:

  • senderDeviceId:uint16_t – deviceID from where message came
  • dataSize:uint16_t – size of incoming messages
  • data:uint8_t* – incoming data
  • returnDataSize:&uint16_t – size of returning data
  • returnData:&uint8_t* – returning data

 

example:

at above example array of 3 bytes will be return by this function to caller device