Virtual Sensor

Introduction

 

QikEasy Adapter’s Virtual Wireless Sensor functionality allows you to wirelessly send measurement data from a custom device to the LEGO hub through HTTP GET requests.

 

By default, the virtual wireless sensor would appear as a Color sensor.  You may easily change it to another sensor type by a URL such as the following:

http://192.168.0.128/set?t=d&d=1500

 

This request would turn QikEasy adapter into a Spike Prime Distance sensor with a raw distance value of 1500 (or real world distance of 150cm).

 

QikEasy Adapter supports these emulated Virtual Devices:

    • Color Sensor (which is the default)
    • Distance Sensor
    • Force Sensor

 

Below is a brief overview of steps involved in setting up your QikEasy Adapter as a Virtual Wireless Sensor:

 

    1. Boot QikEasy Adapter into Setup Mode
    2. Connect your computer or mobile phone to the Adapter’s Setup Mode Wifi Access Point
    3. Connect your browser to the QikEasy Adapter Setup page
    4. In Setup mode, enable the Virtual Wireless Sensor Mode option by providing the credentials to your local Wifi router.

 

See below for more detailed instructions on each step.

Booting QikEasy Adapter into Setup Mode

Before configuring your virtual sensor, you must first set your QikEasy Adapter into Setup mode.

 

Go to the following page for detailed instructions on how to get into Setup Mode.

 

https://qikeasy.com/setupmode/

Configuring your QikEasy Adapter as a Virtual Sensor

In order for other devices to wireless send data to QikEasy Adapter, it must establish a connection to your local Wifi network.  Therefore, part of the configuration procedure is to select the Wifi network and set the password for it.

    1. On the main menu of the QikEasy Adapter Setup Access Point website, select “Configure Virtual Wireless Sensor
    2. Check the checkbox to “Enable Virtual Sensor Mode
    3. Click the textbox for Network Name to scan for nearby Wifi networks.
    4. The Wifi Network with the highest strength will be shown.  If this is not the Wifi network/router you want your QikEasy Adapter to connect to, click the dropdown to select the appropriate network name.
    5. Type in the Password for the Wifi network you selected.
    6. Click “Save Configuration” to complete the setup procedure.
    7. To verify that your new settings are correct, the setup page would start counting down from 10 to 0.
    8. Once the count down is over, your QikEasy Adapter should have rebooted back to Setup mode.  The page would prompt you to reconnect your computer/mobile phone to your QikEasy Adapter’s Setup Mode Wifi Access Point (whose name is provided on the webpage).
    9. If everything goes well, it would show you that the Wifi settings are correct, and show you your QikEasy Adapter’s IP address.

      Note down the assigned IP address. It will be needed for your remote device to send data to this QikEasy Adapter later on.
    10. Click the “Start Virtual Server” button OR press the physical RESET button on the adapter to reboot the Adapter into Virtual Wireless Sensor mode.

 

Here’s the tutorial video for how to setup the QikEasy Virtual Wireless Sensor:

Determining your Virtual Sensor IP Address

As mentioned above, you will need to know this QikEasy Virtual Wireless Sensor’s IP address in order to be able to set its measurement data values remotely.  There are a couple possible ways to determine this IP address.

 

Method 1: The Virtual Sensor Setup Process

As above, at the end of the initial Virtual Sensor setup process, our web user interface will display the virtual sensor’s IP address.

 

Method 2: Through a Word Block program

Every time upon bootup of the Virtual Wireless Sensor, the device will start in virtual Color Sensor mode, and will preset its measurements based on the IP address. It is possible to use a Word Block program to read these measurements and display the IP address on your Spike Prime hub.

 

For example, when the IP address is 123.0.1.45, the color sensor measurements will be set as in this table:

MeasurementValueDescription
Red (Ranges from 0 to 1024)123First IP address number
Green (Range from 0 to 1024)0 x 1024 / 255Second IP address number
Blue value (Range from 0 to 1024)1 x 1024 / 255Third IP address number
Color (discrete color. Ranges from -1 to 10)1 x 1024 / 255The hundreds digit of the 4th IP address number
Reflected Light (Ranges from 0 to 100)45The tens and units digits of the 4th IP address number

We recommend that you use a program to display the IP address.  You should run this program immediately after you start your hub that has  the Virtual Sensor connected.  You may store this program into one of the hub’s storage positions so that you may run the program any time you need it.

The following is the Word Block program for Spike Prime 3.0. Make sure you remember to change the Port numbers for all the blue blocks to the port that your QikEasy Adapter is connected to.

The following is the Word Block program for Spike Prime 2.0 and Robot Inventor. The difference is mainly due to the fact that Spike Prime 3.0 interprets RGB as 0 to 1024, while the other systems interpret them as 0 to 255. Make sure you remember to change the Port numbers for all the blue blocks to the port that your QikEasy Adapter is connected to.

Reserving a Fixed IP Address for your Virtual Sensor

In most cases, restarting your QikEasy Virtual Sensor within a short period of time will result in your Wifi router assigning it the same IP address as before. However, if you attempt to restart it after several hours or days, your QikEasy adapter will likely be assigned a different IP address. The IP address assignment behavior solely depends on the design of your Wifi router.

 

Especially for long term usage, in many scenarios, it would be useful to ensure that your Virtual Sensor’s assigned IP address always stay the same. This would allow the remote client that sends data updates to  always use the same IP address to send updates.

 

To ensure that your QikEasy Virtual Sensor always gets the same IP address from your Wifi router, you can use a technique called IP address reservation, also known as DHCP reservation or static DHCP. This technique involves configuring the Wifi router to reserve a specific IP address for a particular Wifi client, based on its MAC address.

Here are the steps to set up IP address reservation on most Wifi routers:

 

    1. Determine the MAC address of the Wifi client device that you want to assign a static IP address to. You can usually find the MAC address in the device’s network settings.
    2. Log in to the Wifi router’s configuration page, which can typically be accessed through a web browser using the router’s IP address.
    3. Look for a section in the router’s configuration page called “DHCP Reservation,” “Static DHCP,” or similar.
    4. Add a new reservation, specifying the MAC address of the Wifi client and the IP address you want to assign to it.
    5. Save the changes, and restart the router and the Wifi client device.

 

Once you have set up IP address reservation on your Wifi router, the designated Wifi client will always receive the same IP address every time it connects to the network, as long as the router is configured properly and the reserved IP address is not in use by another device.

 

You may refer to this web page for more details on how to setup IP address reservation.

Wirelessly Send Measurements to your Virtual Sensor

You may change the virtual sensor type and update the measurement values of your QikEasy Virtual Sensor through HTTP requests from any web capable device that can connect to your local network.

 

Request URL Format

All requests to update the Virtual Sensor are HTTP GET requests.  Below is the general format for the requests:

 

http://<Virtual Sensor's IP address>/set?t=<sensor type>&<measurement value updates>

 

The parameter t can accept these values:

ParameterDescription
cSet Virtual Sensor Type to Color Sensor
dSet Virtual Sensor Type to Distance Sensor
fSet Virtual Sensor Type to Force Sensor
iReset the Virtual Sensor to initial state with its IP address

 

The specific measurement values that can be set through HTTP request varies depending on the Virtual Sensor’s current sensor type.  Below are description of the measurements available for each specific virtual sensor type.

 

Color Sensor

ParameterRangeDescription
d-1 to 10Discrete Color. Note: At bootup, this value is initialized to 3 until the device gets an IP address after Wifi gets connected.
r0 to 1024Red in RGB. Note: At bootup, this value is initialized to 2000 until the device gets an IP address after Wifi gets connected.
g0 to 1024Green in RGB.
b0 to 1024Blue in RGB.
R0 to 1024Reflective light.
a0 to 100Ambient light.

 

Note:

    • In Spike App 2 and Robot Inventor’s Word Block programs, the RGB values are scaled to the range [0, 255], while Python code would see these values with range [0, 1024].
    • In Spike App 2 & 3 and Robot Inventor Word Block programs, the Reflective light value is scaled to [0, 100], while Python code would see this value with range [0, 1024].
    • Ambient Light measurement value is only available in Python programs.
    • For the measurements d (discrete color), R (reflective light) and a (ambient light), when you make the HTTP request with these parameters equal to ‘a’, it will cause the corresponding measurement value(s) to be automatically calculated from the virtual color sensor’s RGB values.

 

 

Distance Sensor

ParameterRangeDescription
d0 to 2500Distance.

 

Note:

    • Word Block scales the range down by a factor of 10.  For example, a raw value of 2000 would be displayed as 200cm in the Word Block program.
    • Word Block’s maximum display value is 200cm.  This means any raw value 2000 and above would yield the same value in your Word Block program.
    • With Python code, you will be able to use the full range from 0 to 2500.

 

 

Force Sensor

ParameterRangeDescription
f0 to 100Force.

 

Note:

    • Word Block scales the range down by a factor of 10.  For example, a raw value of 100 would be displayed as 10 Newton in the Word Block program.
    • With Python code, you will be able to use the full range from 0 to 100.

 

 

Examples

The following are some valid example HTTP requests (where the IP address of the QikEasy Virtual Sensor is 192.168.11.231):

 

http://192.168.11.231/set?t=c&d=3&r=200&g=200&b=200&R=a

This request would configure the QikEasy Virtual Sensor as a Color Sensor with RGB value of {200, 200, 200}, Discrete Color value of 3, and Reflective Light value being calculated based on the aforementioned RGB value.

 

http://192.168.11.231/set?t=d&d=1900

This request would configure the QikEasy Virtual Sensor as a Distance Sensor with a distance of 190cm.

 

http://192.168.11.231/set?t=f&f=80

This request would configure the QikEasy Virtual Sensor as a Force Sensor with a force of 8 Newton.

 

http://192.168.11.231/set?t=i

This request would reset the QikEasy Virtual Sensor to a Color Sensor with initial measurement values set for its IP address.

Example Use Cases

    • Wirelessly Control your Robot
    • Collect data wirelessly from your custom Measuring Instrument (e.g. real time clock, temperature sensor, other environmental sensor)
    • Control your Robot through Alexa or other voice assistant

 

Some other project ideas

    • Integration with Raspberry Pi through HTTP
    • An Extremely Accurate LEGO Clock based on an Internet time protocol (NTP)
    • QR Code triggered robotic action, which uses your mobile phone for QR code scanning
    • Use LEGO to build smart home devices using something like IFTTT
    • iPhone/iPad and Android events to trigger LEGO robotic action, using ShortCuts on iOS, and Tasker on Android.

 

We are always exploring new use cases for this exciting capability.  I encourage you to email us with your ideas at info@novavolta.com. If we like your ideas, we may actually implement the ideas, make videos and write articles on them.