-->
Page 1 of 1

Wireless Sensor Network Robot - Mesh Example (need help)

PostPosted: Thu Feb 23, 2017 9:56 pm
by macross
Hi all
need help here

I was develope some WSN robot
right now I was using 2 ESP8266, one act as a WSN sensor node and other act as a robot node
that robot was working when got data from other WSN sensor node (right now light up LED would be okay)
I would like to send temperature data sent by WSN sensor node, and light up LED in WSN Robot
when the temperature reach 33 Celcius
the code is based on mesh example, and I was able to send data and get data

the funny problem was
i cant use that data to drive my robot
when I write it on serial the data was "0"
I dont know what to do
need help with this...

for WSN sensor node code (using DHT11 temperature data)
Code: Select all#include <ESP8266WiFi.h>
#include <ESP8266WiFiMesh.h>
#include "DHT.h"

#define DHTPin D4
#define DHTTYPE DHT11   // DHT 11

int temp, humid;
unsigned int request_i = 0;
unsigned int response_i = 0;
String manageRequest(String request);

DHT dht(DHTPin, DHTTYPE);

/* Create the mesh node object */
ESP8266WiFiMesh mesh_node = ESP8266WiFiMesh(ESP.getChipId(), manageRequest);

/**
 * Callback for when other nodes send you data
 *
 * @request The string received from another node in the mesh
 * @returns The string to send back to the other node
 */
String manageRequest(String request)
{
  // Read humidity
  humid = dht.readHumidity();
  Serial.print(humid);
  Serial.print(" Rho,  ");
  // Read Temperature
  temp = dht.readTemperature();
  Serial.print(temp);
  Serial.println(" Celcius");
 
  /* Print out received message */
  Serial.print("received: ");
  Serial.println(request);

  /* return a string to send back */
  char response[60];
  sprintf(response, "Temperature send %d for WSN Robot Node ID %d.", response_i++, ESP.getChipId() );
  return response;
}

void setup()
{
  dht.begin();
  Serial.begin(115200);
  delay(10);

  Serial.println();
  Serial.println();
  Serial.println("Setting up mesh node...");

  /* Initialise the mesh node */
  mesh_node.begin();
}

void loop()
{
  /* Accept any incoming connections */
  mesh_node.acceptRequest();

  /* Scan for other nodes and send them a message */
  char request[60];
  sprintf(request, "Temperature read %d celcius from WSN Sensor Node ID %d.", temp, ESP.getChipId());
  mesh_node.attemptScan(request);

  delay(1000);
}



and for WSN robot code
Code: Select all#include <ESP8266WiFi.h>
#include <ESP8266WiFiMesh.h>

#define led D1

int temp;
unsigned int request_i = 0;
unsigned int response_i = 0;

String manageRequest(String request);

/* Create the mesh node object */
ESP8266WiFiMesh mesh_node = ESP8266WiFiMesh(ESP.getChipId(), manageRequest);

/**
 * Callback for when other nodes send you data
 *
 * @request The string received from another node in the mesh
 * @returns The string to send back to the other node
 */
String manageRequest(String request)
{
  /* Print out received message */
  Serial.print("received: ");
  Serial.println(request);

  /* return a string to send back */
  char response[60];
  sprintf(response, "Temperture data sent %dx for WSN Robot Node ID %d.", response_i++, ESP.getChipId() );
  return response;
}

void setup()
{
  Serial.begin(115200);
  delay(10);

  Serial.println();
  Serial.println();
  Serial.println("Setting up mesh node...");

  /* Initialise the mesh node */
  mesh_node.begin();
  pinMode(led, OUTPUT);
}

void loop()
{
  /* Accept any incoming connections */
  mesh_node.acceptRequest();

  /* Scan for other nodes and send them a message */
  char request[60];
  sprintf(request, "Temperature data %d celcius from WSN Sensor Node ID %d.", temp, ESP.getChipId());
  mesh_node.attemptScan(request);

  Serial.print(temp);
  Serial.println(" celcius");

  if (temp >= 33)
  {
    digitalWrite(led, HIGH);
  }
  else
  {
    digitalWrite(led, LOW);
  }

  delay(1000);
}



the serial monitor capture was
received: Temperature reading 26 celcius from WSN Sensor Node ID 13329Ô ÿ??
0 celcius
0 celcius
0 celcius
received: Temperature reading 26 celcius from WSN Sensor Node ID 13329¼ ÿ??
0 celcius
0 celcius
0 celcius
received: Temperature reading 26 celcius from WSN Sensor Node ID 13329¼ ÿ??
0 celcius
0 celcius
0 celcius
received: Temperature reading 26 celcius from WSN Sensor Node ID 13329¼ ÿ??
0 celcius
0 celcius
0 celcius
received: Temperature reading 26 celcius from WSN Sensor Node ID 13329¼ ÿ??
0 celcius
0 celcius
0 celcius
0 celcius
received: Temperature reading 26 celcius from WSN Sensor Node ID 13329,ÿ??
0 celcius
0 celcius
0 celcius
0 celcius
received: Temperature reading 26 celcius from WSN Sensor Node ID 13329ÿ??
0 celcius
0 celcius



i had weeks trying to solve it, still no progress
any comment and help would be appriciate

Re: Wireless Sensor Network Robot - Mesh Example (need help)

PostPosted: Fri Feb 24, 2017 10:43 am
by martinayotte
In your WSN robot code, the "temp" variable is not used, so it is stay at zero value.

Re: Wireless Sensor Network Robot - Mesh Example (need help)

PostPosted: Fri Feb 22, 2019 7:40 pm
by alvaroxramos
sprintf(response, "Temperature send %d for WSN Robot Node ID %d.",temp + response_i++, ESP.getChipId() );

Re: Wireless Sensor Network Robot - Mesh Example (need help)

PostPosted: Fri Feb 22, 2019 7:44 pm
by alvaroxramos
#include <ESP8266WiFi.h>
#include <ESP8266WiFiMesh.h>
#include "DHT.h"

#define DHTPin D4
#define DHTTYPE DHT11 // DHT 11

int temp, humid;
unsigned int request_i = 0;
unsigned int response_i = 0;
String manageRequest(String request);

DHT dht(DHTPin, DHTTYPE);

/* Create the mesh node object */
ESP8266WiFiMesh mesh_node = ESP8266WiFiMesh(ESP.getChipId(), manageRequest);

/**
* Callback for when other nodes send you data
*
* @request The string received from another node in the mesh
* @returns The string to send back to the other node
*/
String manageRequest(String request)
{

/* Print out received message */
Serial.print("received: ");
Serial.println(request);

humid = dht.readHumidity();
Serial.print(humid);
Serial.print(" Rho, ");
// Read Temperature
temp = dht.readTemperature();
Serial.print(temp);
Serial.println(" Celcius");

/* return a string to send back */
char response[60];
sprintf(response, "Temperature send %d for WSN Robot Node ID %d.",temp );
return response;
}

void setup()
{
dht.begin();
Serial.begin(115200);
delay(10);

Serial.println();
Serial.println();
Serial.println("Setting up mesh node...");

/* Initialise the mesh node */
mesh_node.begin();
}

void loop()
{



/* Accept any incoming connections */
mesh_node.acceptRequest();

/* Scan for other nodes and send them a message */
char request[60];
sprintf(request, "Temperature read %d celcius from WSN Sensor Node ID %d.",temp + ESP.getChipId());
mesh_node.attemptScan(request);

delay(1000);
}