Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
basic_robot
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Illuna-Minetest
basic_robot
Commits
5f8659db
Commit
5f8659db
authored
6 years ago
by
rnd
Browse files
Options
Downloads
Patches
Plain Diff
webcommands for robots using nodejs server
parent
fd9f6593
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
scripts/http/webcommands/minetest_webcommands.js
+31
-0
31 additions, 0 deletions
scripts/http/webcommands/minetest_webcommands.js
scripts/http/webcommands/webcommands.lua
+31
-0
31 additions, 0 deletions
scripts/http/webcommands/webcommands.lua
with
62 additions
and
0 deletions
scripts/http/webcommands/minetest_webcommands.js
0 → 100644
+
31
−
0
View file @
5f8659db
// listen to web request and pass it to minetest, rnd 2018
const
http
=
require
(
'
http
'
);
const
hostname
=
'
192.168.0.10
'
//write address of your router (it will be accessible from internet then if you open firewall for nodejs process)
const
port
=
80
;
var
webreq
=
""
// take request from web and pass it to minetest
const
server
=
http
.
createServer
((
req
,
res
)
=>
{
res
.
statusCode
=
200
;
res
.
setHeader
(
'
Content-Type
'
,
'
text/plain
'
);
if
(
req
.
url
==
'
/favicon.ico
'
)
return
// prevent passing this as request
var
pos
=
(
req
.
url
).
indexOf
(
"
/MT
"
);
if
(
pos
>=
0
)
{
// did request come from minetest? then answer with latest request
res
.
write
(
webreq
);
webreq
=
""
;
res
.
end
();
return
}
//process web request and store it
var
ip
=
req
.
connection
.
remoteAddress
;
webreq
=
ip
+
'
'
+
req
.
url
res
.
write
(
'
request received:
'
+
webreq
);
res
.
end
();
// acknowledge request
return
});
server
.
listen
(
port
,
hostname
,
()
=>
{
console
.
log
(
`Server running at http://
${
hostname
}
:
${
port
}
/`
);
});
\ No newline at end of file
This diff is collapsed.
Click to expand it.
scripts/http/webcommands/webcommands.lua
0 → 100644
+
31
−
0
View file @
5f8659db
-- webcommands : access url like: 192.168.0.10/hello_world
--[[ instructions:
1.download nodejs server from
https://nodejs.org/dist/v10.14.2/node-v10.14.2-win-x86.zip
2. run nodejs server using run.bat
:loop
node --inspect myprogs/minetest_webcommands.js
goto loop
3. run robot and type 'http://192.168.0.10:80/hello this is a test' into browser
(you need to write your router address here, i.e. ip accessible from internet OR lan address)
--]]
if
not
fetch
then
fetch
=
_G
.
basic_robot
.
http_api
.
fetch
;
state
=
0
-- ready to fetch new command
-- WARNING: this is run outside pcall and can crash server if errors!
result
=
function
(
res
)
-- res.data is string containing result
state
=
0
if
not
res
.
succeeded
then
self
.
label
(
"#ERROR: data couldn't be downloaded :\n"
..
minetest
.
serialize
(
res
)
)
return
end
if
res
.
data
==
""
then
return
end
local
req
=
res
.
data
;
req
=
string.gsub
(
req
,
"%%20"
,
"S"
)
if
res
.
data
then
self
.
label
(
os.clock
()
..
' received cmd : '
..
res
.
data
)
end
end
end
if
state
==
0
then
fetch
({
url
=
"http://192.168.0.10/MT"
,
timeout
=
30
},
result
)
state
=
1
end
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment