I am working through the book “Building Wireless Sensor Networks” and am currently on Chapter Four - The Romantic Light Sensor With Feedback. I have copied the sketch from the O’Reilly website into Arduino and am trying to upload it to the Uno board. When I try to verify or upload the sketch I get plenty of errors with the setRemoteState() function. Apparently BYTE had be deprecated so the lines with
Serial.print(value, BYTE);
``` need to be replaced with: ```
Serial.write(value);
```.
I have made the changes but now get more errors, namely, the "call of overloaded 'write(int) is ambiguos" error, which points to several lines in the setRemoteState() function:
Serial.write(0x0); // high part of length (always zero)
…
Serial.write(0x0); // frame id set to zero for no reply
//ID of recipient, or use 0xFFFF for broadcast
Serial.write(00);
Serial.write(00);
Serial.write(00);
Serial.write(00);
Serial.write(00);
Serial.write(00);
The error information that appears for each occurrence is:
RomanticLightFeedback.cpp: In function ‘void setRemoteState(int)’:
RomanticLightFeedback:122: error: call of overloaded ‘write(int)’ is ambiguous
/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino/HardwareSerial.h:58: note: candidates are: virtual size_t HardwareSerial::write(uint8_t)
/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino/Print.h:49: note: size_t Print::write(const char*)
Here is the original code for the setRemoteState() function:
void setRemoteState(int value) { // pass either a 0x4 or and 0x5 to turn the pin on or off
Serial.print(0x7E, BYTE); // start byte
Serial.print(0x0, BYTE); // high part of length (always zero)
Serial.print(0x10, BYTE); // low part of length (the number of bytes that follow, not including checksum)
Serial.print(0x17, BYTE); // 0x17 is a remote AT command
Serial.print(0x0, BYTE); // frame id set to zero for no reply
// ID of recipient, or use 0xFFFF for broadcast
Serial.print(00, BYTE);
Serial.print(00, BYTE);
Serial.print(00, BYTE);
Serial.print(00, BYTE);
Serial.print(00, BYTE);
Serial.print(00, BYTE);
Serial.print(0xFF, BYTE); // 0xFF for broadcast
Serial.print(0xFF, BYTE); // 0xFF for broadcast
// 16 bit of recipient or 0xFFFE if unknown
Serial.print(0xFF, BYTE);
Serial.print(0xFE, BYTE);
Serial.print(0x02, BYTE); // 0x02 to apply changes immediately on remote
// command name in ASCII characters
Serial.print(‘D’, BYTE);
Serial.print(‘1’, BYTE);
// command data in as many bytes as needed
Serial.print(value, BYTE);
// checksum is all bytes after length bytes
long sum = 0x17 + 0xFF + 0xFF + 0xFF + 0xFE + 0x02 + ‘D’ + ‘1’ + value;
Serial.print( 0xFF - ( sum & 0xFF) , BYTE ); // calculate the proper checksum
delay(10); // safety pause to avoid overwhelming the serial port (if this function is not implemented properly)
}
Has anyone worked through this exercise and figured out how to make it work?
Thanks!