My hex editor says that character is code 0xE5
Not sure if that helps though !
My hex editor says that character is code 0xE5
Not sure if that helps though !
That definitely helped!!! Thank you.
That hex value is not what I was trying to get. I needed "0x0D".
Okay...
I have made some progress today. I can now get hercules to put the module both in and out of command mode by sending commands in hex.
But.... before we continue, what exactly is this... \r
It returns "5c 72" in hex, when what I need to send is "0D".
PS: I know what "\r" is and what it does. I'm asking what it is supposed to translate to in hex or binary...
Because this module is looking for a definite/exact string, and "\r" is not received as a "".
EDIT: Can I use this to send everything in hex?
byte message[] = {0xAA, 0xBB, 0xCC, 0xDD };
Serial.write(message, sizeof(message));
\r is either 0x0d or 0x0a. I'd need to look it up
Often these types of modules require both of these at the end of a command
You can use. '\r' in your message code to insert that character as single quotes are treated as a single byte character
But you should be able to just send strings like
"AT+WSCAN\n\r"
Not sure which way around the new line and return chars need to be sent as I don't have access to my code at the moment as I'm using my iPad
Here is some progress! ![]()
#include <SoftwareSerial.h>
SoftwareSerial mySerial(10, 11); // RX, TX
void setup() {
// initialize both serial ports:
Serial.begin(9600);
mySerial.begin(9600);
// byte gocommando[] = {0x2B, 0x2B, 0x2B}; //enter "command mode"
// mySerial.write(gocommando, sizeof(gocommando));
// delay(1); // delay in between reads for stability
byte checkserial[] = {0x41, 0x54, 0x2B, 0x0D}; //send "AT+" to confirm serial connection
mySerial.write(checkserial, sizeof(checkserial));
delay(10); // delay in between reads for stability
byte openGPIO[] = {0x41, 0x54, 0x2B, 0x26, 0x44, 0x42, 0x47, 0x3D, 0x21, 0x32, 0x0D}; //set transceiver control to "open"
mySerial.write(openGPIO, sizeof(openGPIO));
delay(10); // delay in between reads for stability
// byte gotransparent[] = {0x41, 0x54, 0x2B, 0x26, 0x45, 0x4E, 0x54, 0x4D, 0x0D}; //enter "transparent mode"
// mySerial.write(gotransparent, sizeof(gotransparent));
// delay(10); // delay in between reads for stability
}
void loop() {
// read from port 1, send to port 0:
if (mySerial.available()) {
int inByte = mySerial.read();
Serial.write(inByte);
}
// read from port 0, send to port 1:
if (Serial.available()) {
int inByte = Serial.read();
mySerial.write(inByte);
}
}
I know you've commented it out, but
// byte gocommando[] = {0x2B, 0x2B, 0x2B}; //enter "command mode"
is actually +++
I don't think you need to send as hex at all e.g.
byte checkserial[] = {0x41, 0x54, 0x2B, 0x0D}; //send "AT+" to confirm serial connection
mySerial.write(checkserial, sizeof(checkserial));
is just
mySerial.print("AT+\r");
Other line could be written as
mySerial.print("AT+&DBG=!2\r");
Give it a go and let me know if it works
The reason I did it in hex is because the "\r" isn't transmitted right for some reason.
EDIT: Oh, now it works. Maybe because "AT+&DBG =!2" enabled the serial?
The main issue with your libray (I think it was you that wrote it), is it checks for "+++" response the verify connection. But, "+++" is only needed after switching from transparent mode. Also, in the UARTwifi.ccp file, its sends "AT+", but doesn't return "+OK".
int UARTWifi::sendAT(int timeout)
{
delay(INTER_COMMAND_DELAY);
_serial->print(F("AT+\r"));
return waitCommandComplete(_gResponseBuf,timeout);
}
OK
cool
it will be easier doing it in plain text ![]()
It appears as thought there is a difference between mySerial.print and mySerial.write
For some reason .print doesn't work but .write does...
OK, but you should still be able to use normal text chars with write, as long as you specify the length
Possibly wrap it in another function
e.g. something like this
void myWrite(char *str)
{
mySerial.write(str,strlen(str));
}
Yup, you are correct. ![]()
Any suggestions on the format of this command...
mySerial.write("AT+WJOIN=!4432c8c0db78, 0, 6, 1, '1TekPro'\r");
It returns "invalid command format"
Normally single quotes mean single character
Try using double quotes
Also try simple commands first
e.g. does yours have WSCAN as a function ? or LKSTT ?
ie things that query the state of the device
If these work, then try the more complex commands, because its possible that its one of the paramaters you are using that is wrong
Actually.
Why are you sending multiple arguments to write()
AFIK, it only takes one arguement
Sorry for my last code, I presumed that write() needed data, length, but it just appears to need a string
so the code would be
mySerial.write("AT+WJOIN=!4432c8c0db78, 0, 6, 1, 1TekPro\r");
AT+WSCAN\r returns
+OK=4432c8c0db78,0,6,1,"1TekPro",27
This is the AT+ instructions.
Format: AT+WJOIN <CR>
+OK=<bssid>?<type>?<channel>?<b_encry>?<ssid>?<rssi><CR><LF><CR><LF>
Parameters: BSSID: network BSSID, length of 12 hexadecimal digits in the format 001EE3A34455
Type: network type. Where 0 indicates infra networks, 1 for the adhoc network.
Channel: channel number.
B_encry: encryption mode. Where 0 indicates open mode 1 means encryption mode.
SSID: wireless network name, 1~32 ASCII characters, surrounded by double quotation marks.
RSSI: the network signal strength, does not contain negative sign, dBm, 50 indicate signal strength for -50dBm.
I am trying to do something like this....
wlan_connect(WLAN_SEC_WPA2,
ssidName,
strlen(ssidName),
NULL,
(unsigned char *)AP_KEY,
strlen(AP_KEY));
One of the issues with your previous code was quotes inside quotes
if you need double quotes inside double quotes you need to escape them
e.g.
mySerial.write("AT+WJOIN=!4432c8c0db78, 0, 6, 1, \"1TekPro\"\r");
Some languages allow you to interchange single and double quotes e.g. javascript so that you can put double quotes inside single quoted strings, but as far as I know you can't do this in C because double quotes mean a C String and single quotes mean a single char
Ok, for those who have the same module as me.... here is a sketch to build/edit
Keep in mind I'm new to this and my code might be an eye sore....
Also a BIG thanks to rogerClark and Frédéric_Plante
#include <SoftwareSerial.h>
SoftwareSerial mySerial(10, 11); // RX, TX
void setup() {
Serial.begin(9600);
mySerial.begin(9600);// Software Serial doesn't seem to work above 57600 baud. Hardware serial works at 115200.
mySerial.write("AT+ENCRY=[u]yourencrytiontypenumber[/u]\r"); //0=OPEN, 1=WEP64, 2=WEP128, 3=WPA-PSK (TKIP), 4=WPA-PSK (CCMP/AES), 5=WPA2-PSK (TKIP), 6=WPA2-PSK (CCMP/AES), mine is 7 but it's not listed...
delay(10);
mySerial.write("AT+SSID=\"[u]yourssid[/u]\"\r"); //sets SSID
delay(10);
mySerial.write("AT+KEY=1,0,\"[u]yourpassword/key[/u]\"\r"); //0=HEX 1=ACSII, key=0-4, yourpassword/key
delay(10);
mySerial.write("AT+NIP=[u]0=DHCP 1=STATIC[/u]\r"); //sets ip address
delay(10);
mySerial.write("AT+PMTF\r"); //save all settings to flash
delay(10);
mySerial.write("AT+Z\r"); //restart module
delay(2000);
mySerial.write("AT+WJOIN\r"); //join your network
delay(10);
}
void loop() {
// read from port 1, send to port 0:
if (mySerial.available()) {
int inByte = mySerial.read();
Serial.write(inByte);
}
}
Replace the things between underline tags with your info
Cool
Looks very similar commands to the modules that Frederic and I have.
Odd that Serial.print doesn't work an that Serial.write (mySerial.write) does work
I wonder what the difference is between these two commands, I looked in the docs and it says that write sends binary bytes, but I wasn't aware that print modified the data that it was given, before sending it.
Anyway, I'm glad you are making progress.
Yeah... it seams silly that all that work and confusion was due to something that silly. ![]()
After researching my but off, it seams that the print function sends in plain ASCII and the Carriage Return is somehow sent wrong. I have double and tripple checked, and there IS a difference when translated to HEX. In HEX, it sends each char one after the other """r" (0x5c 0x72) instead of sending it as a command "\r" (0x0D).
So if we look at the binary values (correct me if I'm wrong)
mySerial.print sends 01011100 01110010, and mySerial.write sends 00001101
Also, it seems my module is in command mode by default and just needs to enable RS485 with
mySerial.write("AT+&DBG=!2\r");
Here is the final working sketch. Let me know if you see any errors or things I can do better.
#include <SoftwareSerial.h>
SoftwareSerial mySerial(10, 11); // RX, TX
void setup() {
Serial.begin(9600);
mySerial.begin(9600);// Software Serial doesn't seem to work above 57600 baud. Hardware serial works at 115200.
mySerial.write("AT+&DBG=!2\r"); //enable RS485 transceiver control
// mySerial.write("AT+WSCAN\r"); //scans for networks in range and prints results to Serial
join();
mySerial.write("AT+ENTM\r"); //temporarily enter transparent mode
}
void loop() {
// read from port 1, send to port 0:
if (mySerial.available()) {
int inByte = mySerial.read();
Serial.write(inByte);
}
//your code goes here
}
void join() {
mySerial.write("AT+ENCRY=[u]yourencrytiontypenumber[/u]\r"); //0=OPEN, 1=WEP64, 2=WEP128, 3=WPA-PSK (TKIP), 4=WPA-PSK (CCMP/AES), 5=WPA2-PSK (TKIP), 6=WPA2-PSK (CCMP/AES), mine is 7 but it's not listed...
delay(10);
mySerial.write("AT+SSID=\"[u]yourssid[/u]\"\r"); //sets SSID
delay(10);
mySerial.write("AT+KEY=1,0,\"[u]yourpassword/key[/u]\"\r"); //0=HEX 1=ACSII, key=0-4, yourpassword/key
delay(10);
mySerial.write("AT+NIP=[u]0=DHCP 1=STATIC[/u]\r"); //sets ip address
delay(10);
mySerial.write("AT+PMTF\r"); //save all settings to flash
delay(10);
mySerial.write("AT+Z\r"); //restart module
delay(2000);
mySerial.write("AT+WJOIN\r"); //join your network
delay(10);
}
How would I go about checking a text file on a server for data?
Do you mean how do you get data from a server on the Internet
If so...
If your module at commands are the same as mine, you need to use, the socket connect command
I think it's STCK
This returns a number of the socket
You can then do a socket send to send the http request, like a browser does
Then you need to do multiple socket receives to read the data. The reason you may need to do multiple reads is there is a max read size of 512 bytes on my module