# Data Streaming with Photon on Local Network

**URL:** <https://community.particle.io/t/data-streaming-with-photon-on-local-network/41951>\
**Category:** Cloud\
**Created:** [May 22, 2018, 8:20pm UTC](https://community.particle.io/t/data-streaming-with-photon-on-local-network/41951 "2018-05-22T20:20:00Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![cxiao31](https://avatars.discourse-cdn.com/v4/letter/c/c68b51/32.png) [@cxiao31](https://community.particle.io/u/cxiao31)\
**Post date:** [May 22, 2018, 8:20pm UTC](https://community.particle.io/t/data-streaming-with-photon-on-local-network/41951/1 "2018-05-22T20:20:00Z")

</div>

Hi all,  
I have a Photon that I want to communicate with a computer. I want to transmit data at about 50 hz, a few bytes at a time. Currently, I’m using TCP to connect between my laptop’s hotspot to the photon. The setup works fine with my computer (HP Probook 4540) , but for other laptops (Lenovo Yoga) it does not work well. Ultimately, I want to communicate between a photon and a computer on the same WiFi network. I’ve tried doing this by using my phone’s hotspot, but could not get it to work. I am at a loss for what to do.  
Thanks,  
Charles

For reference, the code I’m using is very similar to the TCP server code sample provided in the documentation.

---

<div class="post-metadata">

**Author:** ![rickkas7](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/rickkas7/32/8681_2.png) [@rickkas7](https://community.particle.io/u/rickkas7)\
**Post date:** [May 22, 2018, 8:25pm UTC](https://community.particle.io/t/data-streaming-with-photon-on-local-network/41951/2 "2018-05-22T20:25:38Z")

</div>

These examples may be helpful:

> **[rickkas7/livegraph](https://github.com/rickkas7/livegraph)**
>
> livegraph - Example program using Particle Photon, node.js, SSE, HTML5 Canvas to do real-time graphing

> **[rickkas7/localserver](https://github.com/rickkas7/localserver)**
>
> localserver - Sample node.js server for communicating with a Particle photon

---

<div class="post-metadata">

**Author:** ![cxiao31](https://avatars.discourse-cdn.com/v4/letter/c/c68b51/32.png) [@cxiao31](https://community.particle.io/u/cxiao31)\
**Post date:** [May 23, 2018, 12:43pm UTC](https://community.particle.io/t/data-streaming-with-photon-on-local-network/41951/3 "2018-05-23T12:43:54Z")

</div>

Hi,  
This appears to be a good solution, but I’m having trouble running the line “node livegraph.js --login user password”. I get the following error message:

“(node:16700) UnhandledPromiseRejectionWarning: TypeError: storage.setItemSync is not a function  
at C:\Users\cokec\localserver-master\localserver-master\lib\cloud.js:78:15  
at   
at process.\_tickCallback (internal/process/next\_tick.js:188:7)  
(node:16700) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)  
(node:16700) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.”

Any idea how to resolve it?

---

<div class="post-metadata">

**Author:** ![rickkas7](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/rickkas7/32/8681_2.png) [@rickkas7](https://community.particle.io/u/rickkas7)\
**Post date:** [May 23, 2018, 2:18pm UTC](https://community.particle.io/t/data-streaming-with-photon-on-local-network/41951/4 "2018-05-23T14:18:43Z")

</div>

2 posts were merged into an existing topic: [Is it possible to stop SPI bus and turn MISO, MOSI and SCK pins to INPUTS?](https://community.particle.io/t/is-it-possible-to-stop-spi-bus-and-turn-miso-mosi-and-sck-pins-to-inputs/41736)

---

<div class="post-metadata">

**Author:** ![rickkas7](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/rickkas7/32/8681_2.png) [@rickkas7](https://community.particle.io/u/rickkas7)\
**Post date:** [May 23, 2018, 3:37pm UTC](https://community.particle.io/t/data-streaming-with-photon-on-local-network/41951/5 "2018-05-23T15:37:56Z")

</div>

The 3.x version of node-persist removes the sync version of calls that are used by localserver and also requires node 7.6

The easiest solution is to use the 2.0.x version of node-persist

```auto
npm install node-persist@2.0.11

```

I updated the README to use this version instead.

---

<div class="post-metadata">

**Author:** ![cxiao31](https://avatars.discourse-cdn.com/v4/letter/c/c68b51/32.png) [@cxiao31](https://community.particle.io/u/cxiao31)\
**Post date:** [May 23, 2018, 4:20pm UTC](https://community.particle.io/t/data-streaming-with-photon-on-local-network/41951/6 "2018-05-23T16:20:45Z")

</div>

That fixes the error message. However, I still cannot get the plots to work in chrome. Is there something I’m missing?  
Edit: The photon is sending the devicerequest event over and over again, but it is not sending out data.  
Edit2: It is a similar issue that post 14 in [Local server in node.js example](https://community.particle.io/t/local-server-in-node-js-example/24233/14) faces  
Edit 3: Fixed the issue. The issue was connecting the photon to the network created by my laptop’s hotspot. Connecting it to my home network along with the laptop fixed the issue

---

<div class="post-metadata">

**Author:** ![cxiao31](https://avatars.discourse-cdn.com/v4/letter/c/c68b51/32.png) [@cxiao31](https://community.particle.io/u/cxiao31)\
**Post date:** [May 24, 2018, 2:57am UTC](https://community.particle.io/t/data-streaming-with-photon-on-local-network/41951/7 "2018-05-24T02:57:57Z")

</div>

Thanks for the help. Is there an easy way to modify the html code for liveimu, so that all the read values are stored on the page? The current setup only has a couple of seconds worth of data available

---

<div class="post-metadata">

**Author:** ![rickkas7](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/rickkas7/32/8681_2.png) [@rickkas7](https://community.particle.io/u/rickkas7)\
**Post date:** [May 24, 2018, 10:20am UTC](https://community.particle.io/t/data-streaming-with-photon-on-local-network/41951/9 "2018-05-24T10:20:17Z")

</div>

Yes, there are any number of ways more data can be saved. There a sample for [saving data to MySQL](https://github.com/rickkas7/mysqlsample-wifi) but the localserver is just a simple node.js server so pretty much anything is possible:

- Buffering samples in memory
- Storing samples in a fast memory-based database (Redis)
- Storing samples in a relational database (MySQL, etc.)
- Storing samples in an object database (CouchDB, etc.)

Then of course you need to figure out how you’re going get the data out and visualize it. At some point it probably becomes advantageous to ditch the localserver example and just use an actual app framework like ExpressJS.

---

<div class="post-metadata">

**Author:** ![cxiao31](https://avatars.discourse-cdn.com/v4/letter/c/c68b51/32.png) [@cxiao31](https://community.particle.io/u/cxiao31)\
**Post date:** [May 24, 2018, 5:17pm UTC](https://community.particle.io/t/data-streaming-with-photon-on-local-network/41951/10 "2018-05-24T17:17:32Z")

</div>

Hmm. I’ll take a look at the MySQL. Is there no way to just modify the html so I can have all the collected values on way page? I plan on copying and pasting the data on to a text file so i can process with MATLAB

---

<div class="post-metadata">

**Author:** ![rickkas7](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/rickkas7/32/8681_2.png) [@rickkas7](https://community.particle.io/u/rickkas7)\
**Post date:** [May 24, 2018, 5:30pm UTC](https://community.particle.io/t/data-streaming-with-photon-on-local-network/41951/11 "2018-05-24T17:30:32Z")

</div>

Oh, sure, you can just print out the data on a web page instead. If you look at the Javascript it receives the values in an event and then plots them. Instead of or in addition to plotting them you could just append them to the page html as text, a table, or whatever.
