Hello guys,
I'm currently working on a project thats called the Smart Window. The purpose of this project is to show the window status (so if it is open or closed). For this purpose i have used a mesh protocol.
To make this data visible i decided to use an Arduino Yùn to upload it to the internet. I have connected one of my mesh modules to the Arduino Yùn via the serial port of the Yùn. The problem tho is that i can't really load variables onto my html page.
The data i receive from the mesh nodes like like this:
XXXX: 00999 (were XXXX is the node number of the mesh module).
the last 3 digits tell me the value of the to the mesh module connected sensor.
Here is my Arduino code:
#include <Bridge.h>
#include <Console.h>
#include <YunServer.h>
#include <YunClient.h>
#include <SoftwareSerial.h>
#define rxPin = 0
#define txPin = 1
// Listen on default port 5555, the webserver on the Yún
// will forward there all the HTTP requests for us.
YunServer server;
SoftwareSerial mySerial (20,21);
int x;
String temperature;
void setup() {
SerialUSB.begin(9600);
pinMode(13, OUTPUT);
digitalWrite(13, LOW);
Console.begin();
Console.println("Ready");
Bridge.begin();
mySerial.begin (9600);
mySerial.println ("Connection with virtual Serial port accomplished");
Serial.begin (9600);
Serial.println("Connection with Serial Port established");
digitalWrite(13, HIGH);
server.listenOnLocalhost();
server.begin();
}
void SW1188();
void SW11DL();
void SW11D2();
void SW117R();
void loop()
{
// Get clients coming from server
YunClient client = server.accept();
if (client)
{
String command = client.readString();
command.trim();
if (command == "SW1188")
{
SW1188();
}
if (command == "SW11DL")
{
SW11DL();
}
if (command == "SW11D2")
{
SW11D2();
}
if (command == "SW117R")
{
SW117R();
}
else {
Console.println ("There is no such device connected to our network, we're sorry for the inconvenience");
}
}
client.stop();
delay(150); // Poll every 50ms
}
void SW1188()
{
YunClient client = server.accept();
bool same=0;
char nodeid[]="1188";
while(same == 0){
int positie = 0;
int data[11];
char str[11];
for(int i = 0; i <11; i++){
data = 0;
_ str = 0;_
* }*
* while(mySerial.available()){*
* data[positie] = mySerial.read();*
* positie++;*
* }*
* if(data[0]){*
* for(int i = 0; i<11; i++){*
str = data*;*
* }*
* for(int i =0; i<4; i++){*
if(str != nodeid*){*
* break;*
* }else if(i == 3){ // aantal nodes*
* same = 1;*
* }*
* }*
* }*
* if(same=1){*
* for(int i = 5; i<11; i++){*
_ client.print( "str*)");*_
* }*
* }*
* }*
}
void SW11DL()
{
YunClient client = server.accept();
bool same=0;
char nodeid[]="11DL";
* while(same == 0){*
* int positie = 0;*
* int data[11];*
* char str[11];*
* for(int i = 0; i <11; i++){*
_ data = 0;
str = 0;
* }
while(mySerial.available()){
data[positie] = mySerial.read();
positie++;
}
if(data[0]){
for(int i = 0; i<11; i++){_
str _= data;
}
for(int i =0; i<4; i++){_
if(str _!= nodeid){
break;
}else if(i == 3){
same = 1;
}
}
}
if(same){
for(int i = 5; i<11; i++){
client.println( "str)");*_
* }*
* }*
* }*
}
* void SW11D2()*
{
YunClient client = server.accept();
bool same=0;
* char nodeid[]="11D2";*
* while(same == 0){*
* int positie = 0;*
* int data[11];*
* char str[11];*
* for(int i = 0; i <11; i++){*
_ data = 0;
str = 0;
* }
while(mySerial.available()){
data[positie] = mySerial.read();
positie++;
}
if(data[0]){
for(int i = 0; i<11; i++){_
str _= data;
}
for(int i =0; i<4; i++){_
if(str _!= nodeid){
break;
}else if(i == 3){
same = 1;
}
}
}
if(same){
for(int i = 5; i<11; i++){
client.println( "str)");
}*_
* }*
* }*
}
* void SW117R()*
{
YunClient client = server.accept();
bool same=0;
char nodeid[]="117R";
* while(same == 0){*
* int positie = 0;*
* int data[11];*
* char str[11];*
* for(int i = 0; i <11; i++){*
_ data = 0;
str = 0;
* }
while(mySerial.available()){
data[positie] = mySerial.read();
positie++;
}
if(data[0]){
for(int i = 0; i<11; i++){_
str _= data;
}
for(int i =0; i<4; i++){_
if(str _!= nodeid){
break;
}else if(i == 3){
same = 1;
}
}
}
if(same){
for(int i = 5; i<11; i++){
client.println( "str)");
}
}
}*_
}
Since I'm new to HTML and Javascript i don't really know how to solve this problem. My current HTML page looks like this:
* *
*
Welcome To The Smart Window!
* Node 1188 : 0*
* Node 11DL : 0*
* Node 11D2 : 0*
* Node 117R : 0*
* *
The thing i want to achieve is that my html page loads the current sensor values and displays these.
If anyone could point me in the right direction that would be amazing.
Regards,
Yorick