Intel® Makers
Intel® Edison, Intel® Joule™, Intel® Curie™, Intel® Galileo
Announcements
Welcome - This is a Peer-to-Peer Forum only. Intel has discontinued these products but you may find support from other customers on this Forum
9881 Discussions

connect node js with html button

AMura5
Beginner
1,091 Views

hi everyone

i'm working on robot has Intel Edison board and i need to connect the html button and make it a server can anyone help me this is the node code and html code :

app.js:

/*Http server*/

var express = require("express");

var app = express();

var http = require('http').Server(app);

var path = __dirname + '/';

var io = require('socket.io')(http);

var myip = require('quick-local-ip');

var PORT = 4000;

// INTEL EDISON CONTROLL PART----------------------------------------------------

//MRAA Initialization

var m = require("mraa");

var u = new m.Uart(0); //Default

u.setBaudRate(9600);

u.setMode(8,0,1);

u.setFlowcontrol(false, false);

sleep(200);

var command = new Buffer(4);

command[0] = 0x22;

command[1] = 0x00;

command[2] = 0x00;

command[3] = 0x22;

function isObjectClose(threshold) {

var rxBuf;

var result;

u.write(command);

sleep(200);

rxBuf = u.read(4);

sleep(200);

if (rxBuf[3] == (rxBuf[0]+rxBuf[1]+rxBuf[2])) {

result = (rxBuf[1]<<8) | rxBuf[2];

if (result < threshold)

return true;

else

return false;

}

else

return true;

}

var x = new m.I2c(0);

x.address(4);

var buf = new Buffer(5);

buf[0] = 0x55; //Header 1

buf[1] = 0xaa; //Header 2

function tankForward(speed) {

if (speed > 0xFF)

speed = 0xFF;

//Left Motor CounterClockwise

buf[2] = 0xB1;

buf[3] = 0x1;

buf[4] = (buf[0]+buf[1]+buf[2]+buf[3]) & 0xFF;

x.write(buf);

//Right Motor CounterClockwise

buf[2] = 0xB2;

buf[3] = 0x1;

buf[4] = (buf[0]+buf[1]+buf[2]+buf[3]) & 0xFF;

x.write(buf);

//Left Motor Speed

buf[2] = 0xC1;

buf[3] = speed;

buf[4] = (buf[0]+buf[1]+buf[2]+buf[3]) & 0xFF;

x.write(buf);

//Right Motor Speed

buf[2] = 0xC2;

buf[3] = speed;

buf[4] = (buf[0]+buf[1]+buf[2]+buf[3]) & 0xFF;

x.write(buf);

}

function tankBackward(speed) {

if (speed > 0xFF)

speed = 0xFF;

//Left Motor Clockwise

buf[2] = 0xB1;

buf[3] = 0x0;

buf[4] = (buf[0]+buf[1]+buf[2]+buf[3]) & 0xFF;

x.write(buf);

//Right Motor Clockwise

buf[2] = 0xB2;

buf[3] = 0x0;

buf[4] = (buf[0]+buf[1]+buf[2]+buf[3]) & 0xFF;

x.write(buf);

//Left Motor Speed

buf[2] = 0xC1;

buf[3] = speed;

buf[4] = (buf[0]+buf[1]+buf[2]+buf[3]) & 0xFF;

x.write(buf);

//Right Motor Speed

buf[2] = 0xC2;

buf[3] = speed;

buf[4] = (buf[0]+buf[1]+buf[2]+buf[3]) & 0xFF;

x.write(buf);

sleep(2000);

}

app.get('/', function(req, res){

// console.log(res)

res.sendFile(__dirname + '/index.html');

});

http.listen(PORT, function(){

console.log('--------------------------------------------------------------');

console.log('-------------------------Loading Server-----------------------');

console.log('--------------------------------------------------------------\n');

console.log('Server IP : '+myip.getLocalIP4()+' Port : '+PORT);

});

-------------------------------------------------------------------------

and html is:

<!DOCTYPE html>

Robot as a Website

<!-- make the header for the website to write the name for the project-->

rbot as a websit

<!-- <img src="img/robot.jpg" id="img"> -->

0 Kudos
1 Reply
idata
Community Manager
154 Views

Hello morire,

Thank you for your interest in Intel® Edison Breakout Board.

I understand that you want to program an HTML button that makes the Intel Edison act as a server.

I think this project is more code-oriented than Edison-oriented, in the sense that you are not experiencing any issue with the board itself, which makes your inquiry out of the scope of this technical support team.

What I can do is recommend you a link that may help you turn your Edison into a Webserver using Node.js:

How to Make a Basic Webserver on the Intel® Edison Using Node.js

 

https://software.intel.com/en-us/videos/how-to-make-a-basic-webserver-on-the-intel-edison-using-node... https://software.intel.com/en-us/videos/how-to-make-a-basic-webserver-on-the-intel-edison-using-node...

Have a nice day.

Regards,

 

Andres V.

 

Reply