chunlinhan / WiFiRM04

Arduino WiFi library for Hi-Link HLK-RM04 module
37 stars 28 forks source link

Compiling for Arduino Uno #3

Open klaasdc opened 10 years ago

klaasdc commented 10 years ago

I'm trying to compile the library for an Arduino Uno, since I have this module as a shield version ( http://ledsee.com/index.php/arduino-modules2013-02-16-10-32-17/arduino-shields/wifi-arduino-schield-detail )

The Uno has only 1 serial port, so I changed

#define AT_DRV_SERIAL Serial

inside at_drv.cpp, and set

#define MAX_SOCK_NUM to 1

inside "wl_definitions.cpp" to avoid Serial1 and Serial2 not defined error

But now I get new errors:

Arduino: 1.0.5 (Windows NT (unknown)), Board: "Arduino Uno"
C:\Program Files (x86)\Arduino\hardware\tools\avr\bin\avr-g++ -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=105 -IC:\Program Files (x86)\Arduino\hardware\arduino\cores\arduino -IC:\Program Files (x86)\Arduino\hardware\arduino\variants\standard -IC:\Program Files (x86)\Arduino\libraries\SoftwareSerial -IC:\Program Files (x86)\Arduino\libraries\WiFiRM04 C:\Users\KlaasDC\AppData\Local\Temp\build374150616553823502.tmp\ScanNetworks.cpp -o C:\Users\KlaasDC\AppData\Local\Temp\build374150616553823502.tmp\ScanNetworks.cpp.o 

  Using previously compiled: C:\Users\KlaasDC\AppData\Local\Temp\build374150616553823502.tmp\SoftwareSerial\SoftwareSerial.cpp.o

C:\Program Files (x86)\Arduino\hardware\tools\avr\bin\avr-g++ -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=105 -IC:\Program Files (x86)\Arduino\hardware\arduino\cores\arduino -IC:\Program Files (x86)\Arduino\hardware\arduino\variants\standard -IC:\Program Files (x86)\Arduino\libraries\SoftwareSerial -IC:\Program Files (x86)\Arduino\libraries\WiFiRM04 -IC:\Program Files (x86)\Arduino\libraries\WiFiRM04\utility C:\Program Files (x86)\Arduino\libraries\WiFiRM04\WiFiRM04.cpp -o C:\Users\KlaasDC\AppData\Local\Temp\build374150616553823502.tmp\WiFiRM04\WiFiRM04.cpp.o 

C:\Program Files (x86)\Arduino\libraries\WiFiRM04\WiFiRM04.cpp:11: error: too many initializers for 'int16_t [1]'
C:\Program Files (x86)\Arduino\libraries\WiFiRM04\WiFiRM04.cpp:12: error: too many initializers for 'uint16_t [1]'

Is the code only meant for Arduino Mega? Thanks

cloudycliff commented 10 years ago

You have to make some changes in WiFiRM04.cpp, line 11 and line 12:

int16_t WiFiRM04Class::_state[MAX_SOCK_NUM] = { NA_STATE }; uint16_t WiFiRM04Class::_server_port[MAX_SOCK_NUM] = { 0 };

klaasdc commented 10 years ago

Thanks! It compiles now, but haven't tested it on the board yet.

Anyway, I added some preprocessor commands to automate selection: In WiFiRM04.cpp, line 11:

#if MAX_SOCK_NUM == 1
int16_t     WiFiRM04Class::_state[MAX_SOCK_NUM] = { NA_STATE };
uint16_t    WiFiRM04Class::_server_port[MAX_SOCK_NUM] = { 0 };
#else
int16_t     WiFiRM04Class::_state[MAX_SOCK_NUM] = { NA_STATE, NA_STATE };
uint16_t    WiFiRM04Class::_server_port[MAX_SOCK_NUM] = { 0, 0 };
#endif

In at_drv.cpp, line 41:

#if defined(__AVR_ATmega328P__)//Arduino Uno
    //Only one Serial port available
    #define AT_DRV_SERIAL Serial
#elif defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)//Arduino Mega
    // use Serial1 as default serial port to communicate with WiFi module
    #define AT_DRV_SERIAL Serial1
    // use Serial2 to communicate the uart2 of our WiFi module
    #define AT_DRV_SERIAL1 Serial2
#endif

In at_drv.cpp, line 2213:

#ifdef AT_DRV_SERIAL1 //Check if 2nd serial port is to be used
HardwareSerial AtDrv::serialPort[] = {AT_DRV_SERIAL, AT_DRV_SERIAL1};
#else
HardwareSerial AtDrv::serialPort[] = {AT_DRV_SERIAL, AT_DRV_SERIAL};
#endif

KlaasDC

chunlinhan commented 10 years ago

Hi,

Thank for your suggestion. I've fixed this issue.

KrithikaRaja commented 9 years ago

i use arduino uno and did the following changes:

define AT_DRV_SERIAL Serial

inside at_drv.cpp, and set

define MAX_SOCK_NUM to 1

inside "wl_definitions.cpp"

Still i get the same error while compiling as, \utility\at_drv.cpp:2207: error: 'Serial1' was not declared in this scope \utility\at_drv.cpp:2207: error: 'Serial2' was not declared in this scope

Looking forward for suggestions to set this right and make the module work.

chunlinhan commented 9 years ago

Hi KrithikaRaja,

Try to define both AT_DRV_SERIAL and AT_DRV_SERIAL1 as Serial as the following:

define AT_DRV_SERIAL Serial

define AT_DRV_SERIAL1 Serial

KrithikaRaja commented 9 years ago

Hello, I've rectified that. Thank you for your response. I have another query. I connected the module with my home network. I'm able to scan the available network through the program. But when I try to connect it with WPA network, I get 'echo no response, can't switch to at mode ' in the serial window. Where have i gone wrong ? Pls guide me. I use arduino mega 2560 and hlk -rm04 Wi-Fi module On 17 Mar 2015 11:55, "chunlinhan" notifications@github.com wrote:

Hi KrithikaRaja,

Try to define both AT_DRV_SERIAL and AT_DRV_SERIAL1 as Serial as the following:

define AT_DRV_SERIAL Serial

define AT_DRV_SERIAL1 Serial

— Reply to this email directly or view it on GitHub https://github.com/chunlinhan/WiFiRM04/issues/3#issuecomment-82142502.

chunlinhan commented 9 years ago

Hi KrithikaRaja,

Would you mind to show me the debug message? BTW, the sketch you're using is "ConnectWithWPA.ino" ?

KrithikaRaja commented 9 years ago

Hello, Thank you so much for your kindness! I've just fixed it. It's working. Thanks again! On 17 Mar 2015 12:42, "chunlinhan" notifications@github.com wrote:

Hi KrithikaRaja,

Would you mind to show me the debug message? BTW, the sketch you're using is "ConnectWithWPA.ino" ?

— Reply to this email directly or view it on GitHub https://github.com/chunlinhan/WiFiRM04/issues/3#issuecomment-82170599.