Good morning,
1) In order send command from mySignals HW v1 to Xbee i used this code. But answer is always 0 and it's sending AT every 2 seconds. This module does not start.
#include <MySignals.h>
#include <Wire.h>
#include "SPI.h"
void setup()
{
//Write here you correct baud rate
Serial.begin(115200);
MySignals.begin();
//Enable 3G module power -> bit0:0
bitClear(MySignals.expanderState, EXP_3G_ON);
MySignals.expanderWrite(MySignals.expanderState);
MySignals.initSensorUART();
MySignals.enableSensorUART(EXPANSION);
delay(2000);
// checks if the module is started
uint8_t answer = sendATcommand("AT", "OK", 2000);
if (answer == 0)
{
delay(3000);
// waits for an answer from the module
while (answer == 0)
{
// Send AT every two seconds and wait for the answer
answer = sendATcommand("AT", "OK", 2000);
}
}
MySignals.println("Connecting Xbee");
sendATcommand("AT+ATID?", "OK", 6000);
sendATcommand("AT+ATSH?", "OK", 6000);
sendATcommand("AT+ATSL?", "OK", 6000);
delay(1000);
}
void loop()
{
delay(5000);
}
int8_t sendATcommand(char* ATcommand, char* expected_answer1, unsigned int timeout)
{
uint8_t x = 0, answer = 0;
char response[500];
unsigned long previous;
memset(response, '\0', 100); // Initialize the string
delay(100);
while ( Serial.available() > 0) Serial.read(); // Clean the input buffer
delay(1000);
Serial.println(ATcommand); // Send the AT command
x = 0;
previous = millis();
// this loop waits for the answer
do {
if (Serial.available() != 0)
{
response[x] = Serial.read();
x++;
// check if the desired answer is in the response of the module
if (strstr(response, expected_answer1) != NULL)
{
answer = 1;
MySignals.println(response);
}
}
// Waits for the asnwer with time out
}
while ((answer == 0) && ((millis() - previous) < timeout));
return answer;
}
This is a screen shoot of the outout of this code.
https://photos.app.goo.gl/wCxtSRPnvLW5aFgk2 Have you got any idea about this problem?
2) If i want to send data from the shield to Xbee should i use this code ?:
String toSend="abc";
int len =toSend.length();
String lengt=String(len);
String cmd="AT+CIPSEND=";
cmd+=lengt;
sendATcommand(cmd,"OK",20000);
sendATcommand(toSend,"OK",20000);
3) Can i pair the 2 Xbee with using AT command by defining the XBee Destination
Address on the first Xbee and by defining The the same ID and CH parameter for both xbee?
Regards.