marcoschwartz / aREST

A RESTful environment for Arduino
http://aREST.io/
Other
1.2k stars 279 forks source link

Compilation Error: conversion from 'String' to 'char*' #27

Closed dextergiii closed 9 years ago

dextergiii commented 9 years ago

Hello,

I am currently working from the Arduino Home Automation Projects book in chapter 1. When I load the following code, I get a compilation error as shown below:

I'm using the IDE 1.5.8 if that helps. Thank you for any guidance.

Code: // Libraries

include

include

// Motion sensor ID String xbee_id = "2";

// Create ArduREST instance aREST rest = aREST();

void setup() {

// Start Serial Serial.begin(9600);

// Give name and ID to device rest.set_id(xbee_id); }

void loop() {

// Handle REST calls rest.handle(Serial);

}

Error Message:
HomeAuto_Chap1_RevA.ino.ino: In function 'void setup()': HomeAuto_Chap1_RevA.ino.ino:17:22: error: no matching function for call to 'aREST::set_id(String&)' HomeAuto_Chap1_RevA.ino.ino:17:22: note: candidate is: In file included from HomeAuto_Chap1_RevA.ino.ino:3:0: E:\Documents\Arduino\Sketches\libraries\aREST/aREST.h:714:6: note: void aREST::setid(char) void set_id(char *deviceid){ ^ E:\Documents\Arduino\Sketches\libraries\aREST/aREST.h:714:6: note: no known conversion for argument 1 from 'String' to 'char' Error compiling.

frvalle commented 9 years ago

Hi,

I am having the same issue. I changed the xbee_id argument for "2" and was able to compile, but the information that the serial port is returning is incomplete. Please help screen shot 2014-11-12 at 10 55 58 pm

marcoschwartz commented 9 years ago

You're right, I just pushed a new release that should fix the problem. Let me know if it works!

dextergiii commented 9 years ago

Frvalle,

I spent hours trying to figure out why I wasn't seeing the first part of the response. One requirement I didn't see mentioned is that you must select "carriage return" in your serial monitor (where it currently says No Line Ending).

Using the same approach you mentioned, I was able to compile correctly, but the website would not update when the sensor was triggered. I'm wondering if the var "xbee_id" is referenced in the php/java files and bypassing it in the sketch was the wrong approach...or if it is something unrelated. Will soon f find out.

Marco, thanks for the quick response. Wish I would have asked earlier. Some forums have indicated the php_serial.class will not work on Windows. I'm using Windows 7... Have you heard this?

frvalle commented 9 years ago

Hi Marco, thanks for the correction in the library. I tested the library and it's compiling now, but for some reason the ID of the xbee is returning an strange caracter. screen shot 2014-11-13 at 11 49 30 am @dextergiii thank you so much for the "carriage return tip" It solved my problem in the serial monitor

dextergiii commented 9 years ago

Unfortunately, new errors are showing when using the new library:

Arduino: 1.5.8 (Windows 7), Board: "Arduino Yún"

HomeAuto_Chap1_RevA.ino.ino: In function 'void loop()': HomeAuto_Chap1RevA.ino.ino:27:21: error: no matching function for call to 'aREST::handle(Serial&)' HomeAuto_Chap1_RevA.ino.ino:27:21: note: candidates are: In file included from HomeAuto_Chap1RevA.ino.ino:1:0: E:\Documents\Arduino\Sketches\libraries\aREST-7098a65c57aedcdb84d84559b7043f8302aedc65/aREST.h:242:6: note: void aREST::handle(HardwareSerial&) void handle(HardwareSerial& serial){ ^ E:\Documents\Arduino\Sketches\libraries\aREST-7098a65c57aedcdb84d84559b7043f8302aedc65/aREST.h:242:6: note: no known conversion for argument 1 from 'Serial' to 'HardwareSerial&' E:\Documents\Arduino\Sketches\libraries\aREST-7098a65c57aedcdb84d84559b7043f8302aedc65/aREST.h:258:6: note: void aREST::handle(char) void handle(char * string) { ^ E:\Documents\Arduino\Sketches\libraries\aREST-7098a65c57aedcdb84d84559b7043f8302aedc65/aREST.h:258:6: note: no known conversion for argument 1 from 'Serial' to 'char_' Error compiling.

marcoschwartz commented 9 years ago

Alright, thanks for finding the bugs! I just released a new version that fixes the strange characters appearing in the Serial monitor.

For the Yun, so far the library is not compatible with the Yun + Serial communications. I recommend using the Arduino Uno for this project. Also, it's better to use Arduino 1.5.7 for all projects using aREST. Let me know if that helps!

dextergiii commented 9 years ago

Excellent. The code compiled and uploaded without issue. The serial terminal returns the command as highlighted in your book exactly. Thank you for your efforts too resolve.

I'm still having challenges getting the php script to return values and update the html buttons. Perhaps this isn't the right forum for addressing, but I've tried several work arounds and can't resolve. Any guidance for troubleshooting this next step in the chapter?

Thanks again, Dex On Nov 16, 2014 7:37 AM, "marcoschwartz" notifications@github.com wrote:

Alright, thanks for finding the bugs! I just released a new version that fixes the strange characters appearing in the Serial monitor.

For the Yun, so far the library is not compatible with the Yun + Serial communications. I recommend using the Arduino Uno for this project. Also, it's better to use Arduino 1.5.7 for all projects using aREST. Let me know if that helps!

— Reply to this email directly or view it on GitHub https://github.com/marcoschwartz/aREST/issues/27#issuecomment-63219147.

marcoschwartz commented 9 years ago

You're welcome!

For your question, it is well known that the php_serial module doesn't work too well with Windows. Do you have the possibility of trying it with either Linux or OS X ?

frvalle commented 9 years ago

Hi Marco,

I'm using MAC OS (Maverics) and having the same issue. The status of the motion sensor in the html page is not working. I think is something related to the serial php class because a don't see any activity in the serial port that I'm changing in the program.

Thank you

russbrookes commented 9 years ago

I had the same problem with the serial output of /digital/8/r when using rest.handle(Serial) not showing the first part of the expected output. ie .. expected: {return_value": 0, "id": "2", "name": "", "connected": true} actual: "id": "2", "name": "", "connected": true}

Thanks, dextergiii, for the direction above to set the Arduino IDE serial monitor to "carriage return" instead of "no line ending" in the bottom right corner (just to the left of baud rate setting). That solved the problem.

russbrookes commented 9 years ago

Hi Marco, I'm attempting to "Building Wireless XBee Motion Detectors" from your book Arduino Home Automation Projects. I'm using a Windows machine for my EasyPHP webserver, and have an XBee module plugged into the USB port of that machine. It appears as COM13. I've changed the line in XBee.php from $serial_port = "/dev/cu.usbserial-A702LF8B" to $serial_port="COM13", but the coloured block for Sensor 2 does not change colour (I already confirmed by PIR sensor is working and can read if connected DLINE on Arduino and use /digital/8/r command). Any advice?

marcoschwartz commented 9 years ago

Hi there, that should work fine, as you are doing the right thing for the serial port. Can you try to directly plug your Arduino board to the USB port & then use the Serial port corresponding to the USB port instead of the XBee one? Then we'll know if the issue is coming from the XBee module or the code.

russbrookes commented 9 years ago

Thanks. I think I figured it out. I'm using Windows and the php_serial.class.php code is buggy for Windows (it actually has that comment in the code). Using XCTU I can connect the PC to the xbee and have it wirelessly communicate to the other Xbee attached to the arduino. When I send the "/digital/8/r" and a hex 0D string to the port using XCTU the arduino responds every time exactly as expected, even if I do it as fast as every 100ms.

The problem with xbee.php is that it uses php_serial.class.php, which uses the DOS/Windows MODE command, to set each parameter of the port individually. For example it uses mode to set just the baud rate, then it calls mode again to set just the parity, then it uses mode again to set just the number of data bits, parity, etc.. The problem with this approach is that using the dos/windows MODE command with just one parameter causes it to reset some other parameters back to their default parameters. For example if you set parity to none it will automatically set data bits back to 7 even if you had previously called MODE to set the port to 8 data bits. At first I thought I'd just switch the order of setting the port parameters. But due to the fact that multiple parameters when set individually reset some other parameter back to a default, there is no reliable order I could find in which you could set the parameters individually and still end up with 9600, 8, n, 1, xon=off, RTS off, CTS off and to=off.

So what was happening is that by chance with bad port settings sometimes on a read from serial port it would get some characters that were recognizable to xbee.php and Java.js, and it would seem to work. But it was completely random and could happen within a few seconds or 30 seconds or never.

The other problem with the way the the program works is that the port baud rate etc. settings were being set every time Java.js requested a read from the port and Xbee was having to call php_serial.class.php multiple times - once for each port setting (baud, data, parity, etc.)

And since accessing MODE from php can take 1 to 3 seconds every time - these delays were adding up and making it so that under even the best circumstances the info from the sensor attached to the arduino would only be read and transferred back to the web page every 5 to 10 seconds. (And of course each time had garbled characters)

The third problem I found was that the return value I got when the sensor detected motion was 0, but Java.js was turning Sensor 2 indicator Gray if it got a 0, instead of orange.

I might get some time to day to write some some code to handle the serial port more efficiently.

This is the first time I've ever encountered or done any JavaScript or php programming - so this has been quite a learning opportunity for me. I've enjoyed it very much.

Sent from my iPhone

On Jan 25, 2015, at 11:46 AM, marcoschwartz notifications@github.com wrote:

Hi there, that should work fine, as you are doing the right thing for the serial port. Can you try to directly plug your Arduino board to the USB port & then use the Serial port corresponding to the USB port instead of the XBee one? Then we'll know if the issue is coming from the XBee module or the code.

— Reply to this email directly or view it on GitHub.