Need Help in sending data from console to webpage on an express server using socket.io and johnny-fiveforce client disconnect from server with socket.io and nodejsDownload a file from NodeJS Server using ExpressIs it ok to use many socket.io events?Arduino turn on a led for 2 seconds and then turn off and wait 3 seconds and start all over againCreating a toggle switch in AVR assemblyHow to enable LED Arduino toggle HIGH to LOW on NFC selectionControl Arduino using Express JS server and Johnny-FiveSocket.io and Express not sending dataDHT11 Johnny Five gets no dataSending data to another arduino with wifi using johnny-five

How can saying a song's name be a copyright violation?

What is the most common color to indicate the input-field is disabled?

Is there a hemisphere-neutral way of specifying a season?

Modeling an IP Address

Is "remove commented out code" correct English?

What killed these X2 caps?

Why do I get two different answers for this counting problem?

Is it possible to create light that imparts a greater proportion of its energy as momentum rather than heat?

Is the Joker left-handed?

I Accidentally Deleted a Stock Terminal Theme

Anagram holiday

Is it canonical bit space?

Took a trip to a parallel universe, need help deciphering

Did Shadowfax go to Valinor?

Would Slavery Reparations be considered Bills of Attainder and hence Illegal?

Doing something right before you need it - expression for this?

How do I write bicross product symbols in latex?

Were any external disk drives stacked vertically?

Is Lorentz symmetry broken if SUSY is broken?

What is the word for reserving something for yourself before others do?

Can a virus destroy the BIOS of a modern computer?

AES: Why is it a good practice to use only the first 16bytes of a hash for encryption?

Why is Collection not simply treated as Collection<?>

Watching something be written to a file live with tail



Need Help in sending data from console to webpage on an express server using socket.io and johnny-five


force client disconnect from server with socket.io and nodejsDownload a file from NodeJS Server using ExpressIs it ok to use many socket.io events?Arduino turn on a led for 2 seconds and then turn off and wait 3 seconds and start all over againCreating a toggle switch in AVR assemblyHow to enable LED Arduino toggle HIGH to LOW on NFC selectionControl Arduino using Express JS server and Johnny-FiveSocket.io and Express not sending dataDHT11 Johnny Five gets no dataSending data to another arduino with wifi using johnny-five






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








-3















Need help with sending data from the console to the main webpage. The data is stored in Arduino using custom data property provided by the johnny-five framework.



arduino.js ##



const io = require('socket.io-client');
const five = require('johnny-five');
const config = require('./config');

// Connect to the socket server
const socket = io.connect(config.url);

const board = five.Board();

board.on('ready', function()

const led = new five.Led(9); // Set pin 13 for LED



const sensor = new five.Sensor(
pin: "A0",
custom:
a: "Hello",
b: 2,

);
socket.on('call',function()
console.log (sensor.custom.a);
)

// Turn LED on when event led:on is received
socket.on('led:on', function()
led.on();
//this.digitalRead(7,function(value)
//console.log(value);
//);
);

// Turn LED off when event led:off is received
socket.on('led:off', function()
led.off();
);

);


server.js



const express = require('express');
const config = require('./config');
const app = express();

// Development only
if (process.env.NODE_ENV === 'development')
const webpackMiddleware = require('webpack-dev-middleware');
const webpack = require('webpack');
const webpackConfig = require('./webpack.config.js');
app.use(webpackMiddleware(webpack(webpackConfig)));
else
app.use(express.static('dist')); // Set 'dist' folder as static assets folder


const server = app.listen(process.env.PORT || config.port, function() config.port;
console.log('Socket server listening at: ' + port);
);

const io = require('socket.io')(server);

io.of('/arduino').on('connection', (socket) =>

console.log('New connection: ' + socket.id);

socket.on('led:on', function()
socket.broadcast.emit('led:on');
socket.broadcast.emit('call');
console.log('Broadcasting: led:on');
);

socket.on('led:off', function()
socket.broadcast.emit('led:off');
console.log('Broadcasting: led:off');
);

);


index.js



import '../style/style.css';
import io from 'socket.io-client';
import url from '../config';

(function()

const switchElement = document.getElementById('switch');
const maskElement = document.getElementById('mask_container');
const lightElement = document.getElementById('light');
const outputElement = document.getElementById('labelbutton');
let state = false; // Switch state

const setLight = (mode) =>
state = mode === 'toggle' ? !state : mode === 'on';
if(state)
// Turn light on
state = true;
switchElement.classList.add('on');
lightElement.style.display = 'none';
else
// Turn light off
state = false;
switchElement.classList.remove('on');
lightElement.style.display = 'block';

;

const toggle = () =>
// Toggle light/switch
setLight('toggle');

// Emit the event led:on/off when the switch is clicked
socket.emit(`led:$ state ? 'on' : 'off'`);
console.log(`Sent: $state ? 'on' : 'off'`);
;

// Connect to the socket server
const socket = io.connect(url);

// Turn off the LED when the page loads
socket.emit('led:off');

// Add an event listener (click) to the switch to turn the LED on/off
maskElement.addEventListener('click', toggle); // When the light is off
switchElement.addEventListener('click', toggle); // When the light is on


// When the event led:on is received toggle the switch to on
socket.on('led:on', () =>
console.log('Received: on');
setLight('on');
);

// When the event led:off is received toggle the switch to off
socket.on('led:off', () =>
console.log('Received: off');
setLight('off');
);

)();


index.html



<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Johnny Five Sockets</title>
</head>
<body>
<div>
<div id="light">
<div id="mask_container"></div>
</div>
<div id="wall_socket">
<div id="switch_container">
<div class="switch" id="switch"></div>
</div>
</div>

</div>
<label id="labelbutton" class ="call">Output :</label>
</body>
</html>


I need to pass the sensor.custom.a from arduino.js to the <label> in index.html. Any help would be appreciated










share|improve this question



















  • 3





    Please see: Why is “Can someone help me?” not an actual question?

    – Ivar
    Mar 8 at 0:07











  • Welcome to Stack Overflow. You have not provided a problem, 'how do I do this' and 'can you code for me' type questions are not appropriate here. There is no specific question to solve here.

    – Steven Stark
    Mar 8 at 0:08

















-3















Need help with sending data from the console to the main webpage. The data is stored in Arduino using custom data property provided by the johnny-five framework.



arduino.js ##



const io = require('socket.io-client');
const five = require('johnny-five');
const config = require('./config');

// Connect to the socket server
const socket = io.connect(config.url);

const board = five.Board();

board.on('ready', function()

const led = new five.Led(9); // Set pin 13 for LED



const sensor = new five.Sensor(
pin: "A0",
custom:
a: "Hello",
b: 2,

);
socket.on('call',function()
console.log (sensor.custom.a);
)

// Turn LED on when event led:on is received
socket.on('led:on', function()
led.on();
//this.digitalRead(7,function(value)
//console.log(value);
//);
);

// Turn LED off when event led:off is received
socket.on('led:off', function()
led.off();
);

);


server.js



const express = require('express');
const config = require('./config');
const app = express();

// Development only
if (process.env.NODE_ENV === 'development')
const webpackMiddleware = require('webpack-dev-middleware');
const webpack = require('webpack');
const webpackConfig = require('./webpack.config.js');
app.use(webpackMiddleware(webpack(webpackConfig)));
else
app.use(express.static('dist')); // Set 'dist' folder as static assets folder


const server = app.listen(process.env.PORT || config.port, function() config.port;
console.log('Socket server listening at: ' + port);
);

const io = require('socket.io')(server);

io.of('/arduino').on('connection', (socket) =>

console.log('New connection: ' + socket.id);

socket.on('led:on', function()
socket.broadcast.emit('led:on');
socket.broadcast.emit('call');
console.log('Broadcasting: led:on');
);

socket.on('led:off', function()
socket.broadcast.emit('led:off');
console.log('Broadcasting: led:off');
);

);


index.js



import '../style/style.css';
import io from 'socket.io-client';
import url from '../config';

(function()

const switchElement = document.getElementById('switch');
const maskElement = document.getElementById('mask_container');
const lightElement = document.getElementById('light');
const outputElement = document.getElementById('labelbutton');
let state = false; // Switch state

const setLight = (mode) =>
state = mode === 'toggle' ? !state : mode === 'on';
if(state)
// Turn light on
state = true;
switchElement.classList.add('on');
lightElement.style.display = 'none';
else
// Turn light off
state = false;
switchElement.classList.remove('on');
lightElement.style.display = 'block';

;

const toggle = () =>
// Toggle light/switch
setLight('toggle');

// Emit the event led:on/off when the switch is clicked
socket.emit(`led:$ state ? 'on' : 'off'`);
console.log(`Sent: $state ? 'on' : 'off'`);
;

// Connect to the socket server
const socket = io.connect(url);

// Turn off the LED when the page loads
socket.emit('led:off');

// Add an event listener (click) to the switch to turn the LED on/off
maskElement.addEventListener('click', toggle); // When the light is off
switchElement.addEventListener('click', toggle); // When the light is on


// When the event led:on is received toggle the switch to on
socket.on('led:on', () =>
console.log('Received: on');
setLight('on');
);

// When the event led:off is received toggle the switch to off
socket.on('led:off', () =>
console.log('Received: off');
setLight('off');
);

)();


index.html



<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Johnny Five Sockets</title>
</head>
<body>
<div>
<div id="light">
<div id="mask_container"></div>
</div>
<div id="wall_socket">
<div id="switch_container">
<div class="switch" id="switch"></div>
</div>
</div>

</div>
<label id="labelbutton" class ="call">Output :</label>
</body>
</html>


I need to pass the sensor.custom.a from arduino.js to the <label> in index.html. Any help would be appreciated










share|improve this question



















  • 3





    Please see: Why is “Can someone help me?” not an actual question?

    – Ivar
    Mar 8 at 0:07











  • Welcome to Stack Overflow. You have not provided a problem, 'how do I do this' and 'can you code for me' type questions are not appropriate here. There is no specific question to solve here.

    – Steven Stark
    Mar 8 at 0:08













-3












-3








-3








Need help with sending data from the console to the main webpage. The data is stored in Arduino using custom data property provided by the johnny-five framework.



arduino.js ##



const io = require('socket.io-client');
const five = require('johnny-five');
const config = require('./config');

// Connect to the socket server
const socket = io.connect(config.url);

const board = five.Board();

board.on('ready', function()

const led = new five.Led(9); // Set pin 13 for LED



const sensor = new five.Sensor(
pin: "A0",
custom:
a: "Hello",
b: 2,

);
socket.on('call',function()
console.log (sensor.custom.a);
)

// Turn LED on when event led:on is received
socket.on('led:on', function()
led.on();
//this.digitalRead(7,function(value)
//console.log(value);
//);
);

// Turn LED off when event led:off is received
socket.on('led:off', function()
led.off();
);

);


server.js



const express = require('express');
const config = require('./config');
const app = express();

// Development only
if (process.env.NODE_ENV === 'development')
const webpackMiddleware = require('webpack-dev-middleware');
const webpack = require('webpack');
const webpackConfig = require('./webpack.config.js');
app.use(webpackMiddleware(webpack(webpackConfig)));
else
app.use(express.static('dist')); // Set 'dist' folder as static assets folder


const server = app.listen(process.env.PORT || config.port, function() config.port;
console.log('Socket server listening at: ' + port);
);

const io = require('socket.io')(server);

io.of('/arduino').on('connection', (socket) =>

console.log('New connection: ' + socket.id);

socket.on('led:on', function()
socket.broadcast.emit('led:on');
socket.broadcast.emit('call');
console.log('Broadcasting: led:on');
);

socket.on('led:off', function()
socket.broadcast.emit('led:off');
console.log('Broadcasting: led:off');
);

);


index.js



import '../style/style.css';
import io from 'socket.io-client';
import url from '../config';

(function()

const switchElement = document.getElementById('switch');
const maskElement = document.getElementById('mask_container');
const lightElement = document.getElementById('light');
const outputElement = document.getElementById('labelbutton');
let state = false; // Switch state

const setLight = (mode) =>
state = mode === 'toggle' ? !state : mode === 'on';
if(state)
// Turn light on
state = true;
switchElement.classList.add('on');
lightElement.style.display = 'none';
else
// Turn light off
state = false;
switchElement.classList.remove('on');
lightElement.style.display = 'block';

;

const toggle = () =>
// Toggle light/switch
setLight('toggle');

// Emit the event led:on/off when the switch is clicked
socket.emit(`led:$ state ? 'on' : 'off'`);
console.log(`Sent: $state ? 'on' : 'off'`);
;

// Connect to the socket server
const socket = io.connect(url);

// Turn off the LED when the page loads
socket.emit('led:off');

// Add an event listener (click) to the switch to turn the LED on/off
maskElement.addEventListener('click', toggle); // When the light is off
switchElement.addEventListener('click', toggle); // When the light is on


// When the event led:on is received toggle the switch to on
socket.on('led:on', () =>
console.log('Received: on');
setLight('on');
);

// When the event led:off is received toggle the switch to off
socket.on('led:off', () =>
console.log('Received: off');
setLight('off');
);

)();


index.html



<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Johnny Five Sockets</title>
</head>
<body>
<div>
<div id="light">
<div id="mask_container"></div>
</div>
<div id="wall_socket">
<div id="switch_container">
<div class="switch" id="switch"></div>
</div>
</div>

</div>
<label id="labelbutton" class ="call">Output :</label>
</body>
</html>


I need to pass the sensor.custom.a from arduino.js to the <label> in index.html. Any help would be appreciated










share|improve this question
















Need help with sending data from the console to the main webpage. The data is stored in Arduino using custom data property provided by the johnny-five framework.



arduino.js ##



const io = require('socket.io-client');
const five = require('johnny-five');
const config = require('./config');

// Connect to the socket server
const socket = io.connect(config.url);

const board = five.Board();

board.on('ready', function()

const led = new five.Led(9); // Set pin 13 for LED



const sensor = new five.Sensor(
pin: "A0",
custom:
a: "Hello",
b: 2,

);
socket.on('call',function()
console.log (sensor.custom.a);
)

// Turn LED on when event led:on is received
socket.on('led:on', function()
led.on();
//this.digitalRead(7,function(value)
//console.log(value);
//);
);

// Turn LED off when event led:off is received
socket.on('led:off', function()
led.off();
);

);


server.js



const express = require('express');
const config = require('./config');
const app = express();

// Development only
if (process.env.NODE_ENV === 'development')
const webpackMiddleware = require('webpack-dev-middleware');
const webpack = require('webpack');
const webpackConfig = require('./webpack.config.js');
app.use(webpackMiddleware(webpack(webpackConfig)));
else
app.use(express.static('dist')); // Set 'dist' folder as static assets folder


const server = app.listen(process.env.PORT || config.port, function() config.port;
console.log('Socket server listening at: ' + port);
);

const io = require('socket.io')(server);

io.of('/arduino').on('connection', (socket) =>

console.log('New connection: ' + socket.id);

socket.on('led:on', function()
socket.broadcast.emit('led:on');
socket.broadcast.emit('call');
console.log('Broadcasting: led:on');
);

socket.on('led:off', function()
socket.broadcast.emit('led:off');
console.log('Broadcasting: led:off');
);

);


index.js



import '../style/style.css';
import io from 'socket.io-client';
import url from '../config';

(function()

const switchElement = document.getElementById('switch');
const maskElement = document.getElementById('mask_container');
const lightElement = document.getElementById('light');
const outputElement = document.getElementById('labelbutton');
let state = false; // Switch state

const setLight = (mode) =>
state = mode === 'toggle' ? !state : mode === 'on';
if(state)
// Turn light on
state = true;
switchElement.classList.add('on');
lightElement.style.display = 'none';
else
// Turn light off
state = false;
switchElement.classList.remove('on');
lightElement.style.display = 'block';

;

const toggle = () =>
// Toggle light/switch
setLight('toggle');

// Emit the event led:on/off when the switch is clicked
socket.emit(`led:$ state ? 'on' : 'off'`);
console.log(`Sent: $state ? 'on' : 'off'`);
;

// Connect to the socket server
const socket = io.connect(url);

// Turn off the LED when the page loads
socket.emit('led:off');

// Add an event listener (click) to the switch to turn the LED on/off
maskElement.addEventListener('click', toggle); // When the light is off
switchElement.addEventListener('click', toggle); // When the light is on


// When the event led:on is received toggle the switch to on
socket.on('led:on', () =>
console.log('Received: on');
setLight('on');
);

// When the event led:off is received toggle the switch to off
socket.on('led:off', () =>
console.log('Received: off');
setLight('off');
);

)();


index.html



<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Johnny Five Sockets</title>
</head>
<body>
<div>
<div id="light">
<div id="mask_container"></div>
</div>
<div id="wall_socket">
<div id="switch_container">
<div class="switch" id="switch"></div>
</div>
</div>

</div>
<label id="labelbutton" class ="call">Output :</label>
</body>
</html>


I need to pass the sensor.custom.a from arduino.js to the <label> in index.html. Any help would be appreciated







javascript express socket.io arduino johnny-five






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 10 at 15:58









Mr Lister

35.5k1078121




35.5k1078121










asked Mar 8 at 0:02









Aditya JadhavAditya Jadhav

1




1







  • 3





    Please see: Why is “Can someone help me?” not an actual question?

    – Ivar
    Mar 8 at 0:07











  • Welcome to Stack Overflow. You have not provided a problem, 'how do I do this' and 'can you code for me' type questions are not appropriate here. There is no specific question to solve here.

    – Steven Stark
    Mar 8 at 0:08












  • 3





    Please see: Why is “Can someone help me?” not an actual question?

    – Ivar
    Mar 8 at 0:07











  • Welcome to Stack Overflow. You have not provided a problem, 'how do I do this' and 'can you code for me' type questions are not appropriate here. There is no specific question to solve here.

    – Steven Stark
    Mar 8 at 0:08







3




3





Please see: Why is “Can someone help me?” not an actual question?

– Ivar
Mar 8 at 0:07





Please see: Why is “Can someone help me?” not an actual question?

– Ivar
Mar 8 at 0:07













Welcome to Stack Overflow. You have not provided a problem, 'how do I do this' and 'can you code for me' type questions are not appropriate here. There is no specific question to solve here.

– Steven Stark
Mar 8 at 0:08





Welcome to Stack Overflow. You have not provided a problem, 'how do I do this' and 'can you code for me' type questions are not appropriate here. There is no specific question to solve here.

– Steven Stark
Mar 8 at 0:08












0






active

oldest

votes












Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55054775%2fneed-help-in-sending-data-from-console-to-webpage-on-an-express-server-using-soc%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55054775%2fneed-help-in-sending-data-from-console-to-webpage-on-an-express-server-using-soc%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

1928 у кіно

Захаров Федір Захарович

Ель Греко