quarta-feira, 15 de julho de 2020

NINA W102 + VISUINO + THINGSPEAK + ROBLOX

ROBLO-IoT e ThingSpeak (VISUINO enddevice)

The objective of this BLOG is to present a general idea of ​​how the NINA W102 can be controlled by the ROBLOX game and thus turn on or off a lamp when you press a button on the map or not, the count of people who visited the ROBLOX map will be recorded , ThingSpeak was used as a bridge. The enddevice was programmed with VISUINO.

A proposal to use ROBLOX for Internet of Things applications together with ThingSpeak and VISUINO.

Perhaps the first ROBLOX application for IoT (Internet of Things)
ROBLOX


VISUINO


U-BLOX NINA W102

EXECUTION


ROBLOX

Roblox is an MMO (online game with multiple players) and, mainly, a platform for creating and developing games by the users themselves. Unlike Minecraft, which is a sandbox (a game where the player can make and create whatever he wants), Roblox was created as an educational tool to teach physics concepts to children.

Originally launched in 2006, it didn't take long for users to use Roblox (which at the beginning was called DynaBlocks) to create their own games and worlds, with different themes. From there, developer Roblox Corp. opened development and made the tool a free game (out of educational focus).

VISUINO

Visuino is the latest innovative software from Mitov Software. A visual programming environment that allows you to program your Arduino boards. ... The components found in the Visuino software represent your hardware components and you can easily create and design your programs using drag and drop.

SMARTCORE

SmartCore provides modules for wireless communication, biometrics, connectivity, tracking and automation.
Our portfolio includes 2G / 3G / 4G / NB-IoT / Cat.M modem, satellite, WiFi modules, Bluetooth, GNSS / GPS, Sigfox, LoRa, card reader, QR code reader, printing mechanism, mini-board PC, antenna, pigtail, LCD, battery, GPS repeater and sensors.
More details at www.smartcore.com.br

THINGSPEAK


Thingspeak is an IoT (Internet of Things) analysis platform that allows you to aggregate, visualize and analyze data streams, in a very simple way. One of the great advantages of the Thingspeak platform is that it allows us to view the data sent by our devices, in real time, but also the possibility of analyzing them using the powerful Matlab.

VISUINO INSTALLATION

Download it at https://www.visuino.com/ and run


Select the Generic ESP32 module (NINA W102 is based on ESP32)

Add flows as shown below!




JSON extracted from ThingSpeak server



Here it is checked whether the Field has 0 or 1 to turn the LAMP off or on


Every 4 seconds an HTTP request is made on the ThingSpeak server



Transform Characters to Text

Download the Project Here


In the Visuino example, an HTTP request is made to the ThingSpeak server and then a JSON is returned with the current status of the lamp activated by ROBLOX. Depending on the value of the lamp, an LED is on or off locally.

GET em api.thingspeak.com /channels/XXXXXXX/feeds.json?api_key=XXXXXXXXXX&results=1


Resulting in JSON

..."entry_id":220,"field1":"0","field2":"5"}]}


ThingSpeak Configuration
 
1) Create a ThingSpeack account

2)In Channel Settings create two Fields: Field1 and Field2



3) In API keys write down the keys for writing and reading data inThingsSpeak


4) We will then basically have two URLs, one for writing and one for reading the Fields.

https://api.thingspeak.com/update?api_key=XXXXXXXXXXXXXX&field1=X&field2=XXXX
https://api.thingspeak.com/channels/CCCCCCCCC/fields/1.json?api_key=XXXXXXXXXXXXXX
&results=
1

Install the ROBLOX


How to install Roblox
Go to the Roblox website and log in to your account.
When entering Roblox, visit any game and click the green Play button.
A pop-up window will appear informing you that Roblox is installing
Once installed, the game will open automatically.
Note: A secondary pop-up window may appear asking you to select a program. Select Roblox and confirm. If you choose to remember your choice, you do not need to take this action in the future.

Once ROBLOX is installed, either on the PC or on your cell phone, look for ROBLO-IoT




Getting to know ROBLO-IoT, home of the Internet of Things

Visiting the IoT House

On the Left side, the Lamp, on the Right side the Button, both connected with ThingSpeak

When the button is Black, it means off, when pressing it it will turn green and after a few moments the lamp will turn on. Wait 15 seconds for you to press it again, after a few moments the lamp will go out.
Here ROBLOX pressed the button, then the Abajour called and the visit counter increased, all via ThingSpeak

How it works:

Every time Roblox touches the Button, a message via HTTP is sent to ThingSpeak, containing the status of the Button.

Every time the Button is pressed to Call, an update is sent to ThingSpeak of times / visit that the button was pressed.

Every five seconds, Roblox makes a request to ThingSpeak requesting the status of the button, then turns the Lamp on or off according to its value. A panel with visits made by ROBLOX MANIACS worldwide is also updated!

The U-blox board W102 (programmed via VISUINO) every five seconds will make an HTTP request to ThingSpeak about the state of the Button and thus turn an LED on or off.

Via Browser you can change the status of the LAMP or the visit counter.

LUA SCRIPT (JSON was not used)

In Script there are some tips.

local HttpService = game:GetService("HttpService") local Result --Http local URL_ISS --Http request local function printISS() local response local data -- Use pcall in case something goes wrong pcall(function () response = HttpService:GetAsync(URL_ISS) end) if not response then return false end Result=response return true end --Get last ThingSpeak State function Last_State_Counter() wait(5) URL_ISS="https://api.thingspeak.com/channels/1097028/feeds.json?api_key=xxxxxxxxxC&results=1" printISS() --print(Result) --{"channel":{"id":1097028,"name":"ROBLOX","description":"Experimental Test","latitude":"0.0","longitude":"0.0","field1":"Field Label 1","field2":"Field Label 2","created_at":"2020-07-10T18:15:15Z","updated_at":"2020-07-13T00:37:00Z","last_entry_id":179},"feeds":[{"created_at":"2020-07-13T02:17:23Z","entry_id":179,"field1":"1","field2":"7"}]} --Not Using JSON local S_begin, S_end = string.find(Result,"\"field1\":\"",-32) --got 0 or 1 (OFF or ON) local On_Off = string.sub(Result, S_end + 1 , S_end + 1) if On_Off == "0" then workspace.Lamp1.Light.PointLight.Enabled = false State_1=0; workspace.Button1.Button.BrickColor = BrickColor.Black() end if On_Off == "1" then workspace.Lamp1.Light.PointLight.Enabled = true State_1=1; workspace.Button1.Button.BrickColor = BrickColor.Green() end --search at last 32 characters --"field2":"9999"}]} local S_begin, S_end = string.find(Result,"\"field2\":\"",-32) Result = string.sub(Result,S_end+1) --remove "}]} Counter = string.gsub(Result,"\"}]}","") --print(Counter) workspace.Sign.Text.SurfaceGui.TextLabel.Text = "Visits: " .. Counter end --Button Event with Debounce function debounce(func) local isRunning = false -- Create a local debounce variable return function(...) -- Return a new function if not isRunning then isRunning = true func(...) -- Call it with the original arguments isRunning = false end end end workspace.Button1.Button.Touched:Connect(debounce(function(hit) --print("Button 1 pressed, sending IoT info") --Print the message if State_1==0 then --&field = 1 = ON Counter = Counter + 1 URL_ISS = "https://api.thingspeak.com/update?api_key=xxxxxxxxx&field1=1&field2=" .. Counter workspace.Button1.Button.BrickColor = BrickColor.Red() State_1 = 1 else --&field = 0 = OFF URL_ISS = "https://api.thingspeak.com/update?api_key=xxxxxxxxxQ&field1=0&field2=" .. Counter workspace.Button1.Button.BrickColor = BrickColor.Black() State_1 = 0 end printISS() wait(15) --Wait for 15 second to ThingSpeaks accept other command --print(Result) --print("Sent") end)) --Get Last state of ThingSpeak, you can modify direcly on Browser Last_State_Counter() workspace.Sign.Text.SurfaceGui.TextLabel.Text = "Visits: 0000" --Main loop (each 5 seconds, see the State of Key (thingspeak) and Turn On/off a Light! while 1==1 do wait(5) URL_ISS="https://api.thingspeak.com/channels/1097028/feeds.json?api_key=xxxxxxxxx&results=1" printISS() print(Result) --{"channel":{"id":1097028,"name":"ROBLOX","description":"Experimental Test","latitude":"0.0","longitude":"0.0","field1":"Field Label 1","created_at":"2020-07-10T18:15:15Z","updated_at":"2020-07-10T18:15:15Z","last_entry_id":73},"feeds":[{"created_at":"2020-07-10T21:04:30Z","entry_id":72,"field1":"1"},{"created_at":"2020-07-10T23:52:09Z","entry_id":73,"field1":"0"}]} --Not Using JSON :( --search at last 32 characters local S_begin, S_end = string.find(Result,"\"field1\":\"",-32) --got 0 or 1 (OFF or ON) local On_Off = string.sub(Result, S_end + 1 , S_end + 1) --print(On_Off) if On_Off == "0" then workspace.Lamp1.Light.PointLight.Enabled = false workspace.Button1.Button.BrickColor = BrickColor.Black() end if On_Off == "1" then workspace.Lamp1.Light.PointLight.Enabled = true workspace.Button1.Button.BrickColor = BrickColor.Green() end --search at last 32 characters --"field2":"9999"}]} local S_begin, S_end = string.find(Result,"\"field2\":\"",-32) Result = string.sub(Result,S_end+1) --remove "}]} Counter = string.gsub(Result,"\"}]}","") workspace.Sign.Text.SurfaceGui.TextLabel.Text = "Visits: " .. Counter end



Transferring Program to NINA W102 via VISUINO

Compilation and Upload


Questions

Thanks to my son
José Pietro Ferreira Wisintainer, who presented me ROBLOX

Um comentário:

  1. Primeira aplicação para IoT no ROBLOX.
    Várias ferramentas interessantes Em uma abordagem divertida com o ROBLOX.

    Parabéns Miguel, ficou muito interessante. Tenho certeza que foi divertido fazer !!!!!

    ResponderExcluir