ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

I am planning to publish sensor data over wifi module(ESP8266-01) through arduino. In my program it created a access point but it is not sending any data

asked 2017-12-29 10:53:58 -0600

ARUN T S gravatar image

updated 2017-12-29 10:56:13 -0600

#include <SoftwareSerial.h>
#include <SerialESP8266wifi.h>
#include <ros.h>
#include <sensor_msgs/Range.h>
#define sw_serial_rx_pin 12 //  Connect this pin to TX on the esp8266
#define sw_serial_tx_pin 11 //  Connect this pin to RX on the esp8266
 #define esp8266_reset_pin 5 // Connect this pin to CH_PD on the esp8266, not reset. (let reset be unconnected)
 SoftwareSerial swSerial(sw_serial_rx_pin, sw_serial_tx_pin); 
SerialESP8266wifi wifi(swSerial, swSerial, esp8266_reset_pin, Serial);//adding Serial enabled local echo and wifi debug
ros::NodeHandle nh;
sensor_msgs::Range range_msg;
ros::Publisher pub_range("car", &range_msg);
char ultrafrid[] = "/ultrasound";
void setup() {
swSerial.begin(9600);
Serial.begin(9600);
nh.initNode();
nh.advertise(pub_range);
while (!Serial)
Serial.println("Starting wifi");
wifi.setTransportToTCP();
wifi.endSendWithNewline(true); 
wifi.connectToAP("wifissid", "wifipass");
wifi.connectToServer("192.168.4.255", "11411");
wifi.send(SERVER, "ESP8266 test app started");
nh.initNode();
nh.advertise(pub_range);
range_msg.header.frame_id =  ultrafrid;   // ultrasound frame id
range_msg.field_of_view = 0.1;
range_msg.min_range = 0.0;
range_msg.max_range = 20;
}
void loop() {
 if (!wifi.isStarted())      //Make sure the esp8266 is started..
wifi.begin();
for(int i=0;i<5;i++)
{      range_msg.range = i;
}

 pub_range.publish(&range_msg);

nh.spinOnce();
}
edit retag flag offensive close merge delete

Comments

What is your question?

jayess gravatar image jayess  ( 2017-12-29 11:12:36 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
2

answered 2017-12-29 11:21:43 -0600

For the love of all that is good, please learn to indent your code!

There may be a problem with your setup function. you need to add a ; after the while(!Serial) line, this is meant to wait until the serial port is setup, but inside this loop you're writing to the Serial port if it's not setup which may be causing some problems.

while (!Serial);
Serial.println("Starting wifi");

I recommend printing some useful debugging information to the serial port and viewing it from your computer to see what's going on. If you can describe in more detail how this is failing then we'll be able to help you more.

edit flag offensive delete link more

Comments

+1 on the indenting and giving us more information.

jayess gravatar image jayess  ( 2017-12-29 11:25:48 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2017-12-29 10:53:58 -0600

Seen: 1,548 times

Last updated: Dec 29 '17