Arduino Temboo Google Sheets response code 0 returned, still not working - google-sheets

So I'm trying to update a gooogle sheet through Temboo and an Arduino Yun. I can run the AppendValues choreo and AppendRow choreo from the Temboo site just fine and everything updates, but running the choreos through the arduino .ino shows no updates on the google sheet. I get a return code of 0 from running the choreo though. So I know Oauth is working and google and temboo are talking, so there must be a problem in my code?
I have double checked AccountName, Password, AppKey, refresh token, client secret, client id, spreadsheet id, spreadsheet name, etc in the Arduino code (tried AppendValuesChoreo and AppendRowChoreo).
AppendRow .ino:
// Include required libraries
#include <Bridge.h>
#include <Temboo.h>
// Debug mode ?
boolean debug_mode = true;
void setup() {
//start serial
Serial.begin(115200);
delay(4000);
while(!Serial);
// Start bridge
Bridge.begin();
Serial.println("Setup complete. Waiting for sensor input...\n");
}
void loop() {
Serial.println("\nCalling the /Library/Google/Spreadsheets/AppendRow Choreo...");
// Append data to Google Docs sheet
runAppendRow();
// Repeat every 10 seconds
delay(10000);
}
// Function to add data to Google Docs
void runAppendRow() {
TembooChoreo AppendRowChoreo;
// Invoke the Temboo client
AppendRowChoreo.begin();
// Set Temboo account credentials
AppendRowChoreo.setAccountName("");
AppendRowChoreo.setAppKeyName("myFirstApp");
AppendRowChoreo.setAppKey("");
// Identify the Choreo to run
AppendRowChoreo.setChoreo("/Library/Google/Spreadsheets/AppendRow");
// your Google username (usually your email address)
AppendRowChoreo.addInput("Username", "");
// your Google account password
AppendRowChoreo.addInput("Password", "");
// the title of the spreadsheet you want to append to
AppendRowChoreo.addInput("SpreadsheetTitle", "Yun");
// Format data
String data = "123,921";
// Set Choreo inputs
AppendRowChoreo.addInput("RowData", data);
// Run the Choreo
unsigned int returnCode = AppendRowChoreo.run();
// A return code of zero means everything worked
if (returnCode == 0) {
if (debug_mode == true){
Serial.println("Completed execution of the /Library/Google/Spreadsheets/AppendRow Choreo.\n");
Serial.println("Row added: " + data);
}
} else {
// A non-zero return code means there was an error
// Read and print the error message
while (AppendRowChoreo.available()) {
char c = AppendRowChoreo.read();
if (debug_mode == true){ Serial.print(c); }
}
if (debug_mode == true){ Serial.println(); }
}
AppendRowChoreo.close();
}
AppendVValues .ino:
#include <Bridge.h>
#include <Temboo.h>
int calls = 1; // Execution count, so this doesn't run forever
int maxCalls = 10; // Maximum number of times the Choreo should be executed
void setup() {
Serial.begin(9600);
// For debugging, wait until the serial console is connected
delay(4000);
while(!Serial);
Bridge.begin();
}
void loop() {
if (calls <= maxCalls) {
Serial.println("Running AppendValues - Run #" + String(calls++));
TembooChoreo AppendValuesChoreo;
// Invoke the Temboo client
AppendValuesChoreo.begin();
// Set Temboo account credentials
AppendValuesChoreo.setAccountName("");
AppendValuesChoreo.setAppKeyName("");
AppendValuesChoreo.setAppKey("");
// Set Choreo inputs
AppendValuesChoreo.addInput("RefreshToken", "");
AppendValuesChoreo.addInput("ClientSecret", "");
AppendValuesChoreo.addInput("Values", "[[15,49]]");
AppendValuesChoreo.addInput("ClientID", "");
AppendValuesChoreo.addInput("SpreadsheetID", "");
// Identify the Choreo to run
AppendValuesChoreo.setChoreo("/Library/Google/Sheets/AppendValues");
// Run the Choreo; when results are available, print them to serial
AppendValuesChoreo.run();
while(AppendValuesChoreo.available()) {
char c = AppendValuesChoreo.read();
Serial.print(c);
}
AppendValuesChoreo.close();
}
Serial.println("Waiting...");
delay(30000); // wait 30 seconds between AppendValues calls
}

Looks like they only support rev1, and the original shields. Hopefully they'll update services for the rev2 boards soon.

Related

Issue with writing InfluxDB code to ESP32 chip using OTA

I'm trying to write a program for my ESP32 that writes to InfluxDB but also maintains an OTA access server and it appears that the two functions are having some impact on each other that's causing the OTA server to not work (i.e. the OTA page does not appear when I enter the IP address into the browser). I've narrowed the problem down to the
client.writePoint(sensor)
function that InfluxDB uses to write data to buffer and I'm unsure of how to remedy that. The OTA functionality works when I comment out the line that references the above function. I've included this code below.
//PASTE THIS IN ABOVE EXISTING HEADERS
//#include <WiFi.h> //if file already has these libraries, remove it from one of the places
#include <WiFiClient.h>
#include <WebServer.h>
#include <ESPmDNS.h>
#include <Update.h>
const char* host = "esp32";
const char* ssid = "ssid";
const char* password = "pwd";
WebServer server(80);
// end OTA header file
//BEGIN HEADER FILE
#if defined(ESP32)
#include <WiFiMulti.h>
WiFiMulti wifiMulti;
#define DEVICE "TEST"
#elif defined(ESP8266)
#include <ESP8266WiFiMulti.h>
ESP8266WiFiMulti wifiMulti;
#define DEVICE "ESP8266"
#endif
#include <InfluxDbClient.h>
#include <InfluxDbCloud.h>
/* Self inclusions -> Not from InfluxDB */
#define Vdd 3.3
#define Aout 35
#define LINEAR LOW
#define SQ_ROOT HIGH
const int R_0 = -1812; //Change this to your own R0 measurements
#include "max6675.h"
#include <WiFi.h>
#include <WiFiUdp.h>
/* End Self Inclusions */
// InfluxDB v2 server url, e.g. https://eu-central-1-1.aws.cloud2.influxdata.com (Use: InfluxDB UI -> Load Data -> Client Libraries)
#define INFLUXDB_URL "url"
// InfluxDB v2 server or cloud API authentication token ( Data -> Tokens -> MQ Sensors)
#define INFLUXDB_TOKEN "token"
// InfluxDB v2 organization id (Use: InfluxDB UI -> User -> About -> Common Ids )
#define INFLUXDB_ORG "org"
// InfluxDB v2 bucket name (Use: InfluxDB UI -> Data -> Buckets)
#define INFLUXDB_BUCKET "bucket"
// Set timezone string according to https://www.gnu.org/software/libc/manual/html_node/TZ-Variable.html
// Examples:
// Pacific Time: "PST8PDT"
// Eastern: "EST5EDT"
// Japanesse: "JST-9"
// Central Europe: "CET-1CEST,M3.5.0,M10.5.0/3"
#define TZ_INFO "EST5EDT"
// InfluxDB client instance with preconfigured InfluxCloud certificate
InfluxDBClient client(INFLUXDB_URL, INFLUXDB_ORG, INFLUXDB_BUCKET, INFLUXDB_TOKEN, InfluxDbCloud2CACert);
// Data Point
Point sensor("VOC_data"); // Data point
// END HEADER FILE
void setup() { //make sure this line appears one time only
Serial.begin(115200); //make sure there are not two serial/begin functions in setup
Serial.println("started"); //TS COMMENT
// Connect to WiFi network
WiFi.begin(ssid, password);
Serial.println("");
// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("\n\nACCESS UPDATES AT: http://");
Serial.print(WiFi.localIP());
Serial.println("\n\n");
pinMode(Aout, INPUT);
// Add tags
sensor.addTag("device", DEVICE);
// Accurate time is necessary for certificate validation and writing in batches
// For the fastest time sync find NTP servers in your area: https://www.pool.ntp.org/zone/
// Syncing progress and the time will be printed to Serial.
timeSync(TZ_INFO, "pool.ntp.org", "time.nis.gov");
// Check server connection
if (client.validateConnection()) {
Serial.print("Connected to InfluxDB: ");
Serial.println(client.getServerUrl());
} else {
Serial.print("InfluxDB connection failed: ");
Serial.println(client.getLastErrorMessage());
}
/*use mdns for host name resolution*/
if (!MDNS.begin(host)) { //http://esp32.local
Serial.println("Error setting up MDNS responder!");
while (1) {
delay(1000);
}
}
Serial.println("mDNS responder started");
/*return index page which is stored in serverIndex */
server.on("/", HTTP_GET, []() {
server.sendHeader("Connection", "close");
server.send(200, "text/html", loginIndex);
Serial.println("init1 complete"); //TS COMMENT
});
server.on("/serverIndex", HTTP_GET, []() {
server.sendHeader("Connection", "close");
server.send(200, "text/html", serverIndex);
Serial.println("init2 complete"); //TS COMMENT
});
/*handling uploading firmware file */
server.on("/update", HTTP_POST, []() {
server.sendHeader("Connection", "close");
server.send(200, "text/plain", (Update.hasError()) ? "FAIL" : "OK");
ESP.restart();
Serial.println("init3 complete"); //TS COMMENT
}, []() {
HTTPUpload& upload = server.upload();
if (upload.status == UPLOAD_FILE_START) {
Serial.printf("Update: %s\n", upload.filename.c_str());
Serial.println("init4 complete"); //TS COMMENT
if (!Update.begin(UPDATE_SIZE_UNKNOWN)) { //start with max available size
Serial.println("Check at line 201");
Update.printError(Serial);
}
} else if (upload.status == UPLOAD_FILE_WRITE) {
/* flashing firmware to ESP*/
if (Update.write(upload.buf, upload.currentSize) != upload.currentSize) {
Serial.println("Check at line 207");
Update.printError(Serial);
}
} else if (upload.status == UPLOAD_FILE_END) {
if (Update.end(true)) { //true to set the size to the current progress
Serial.printf("Update Success: %u\nRebooting...\n", upload.totalSize);
} else {
Serial.println("Check at line 214");
Update.printError(Serial);
}
}
});
server.begin();
} //delete if void setup() line is deleted
void loop() { //make sure this line does not appear twice
server.handleClient();
float a0 = analogRead(Aout); // get raw reading from sensor
float v_o = a0 * 4.6 / 1023; // convert reading to volts
float R_S = (4.6-v_o) * 1000 / v_o; // apply formula for getting RS
float R_a = R_S/R_0; // formula for the ratio
float PPM = pow(R_a,-2.95) * 1000; //apply formula for getting PPM
float PPM_ALCOHOL = pow(-13.17*log(R_S/R_0) + 10.35 ,1);
//double PPM = pow(static_cast<double>(R_S/R_0),-2.95) * 1000;
//float PPMnew = a0*0.065156122+0.746160521;
sensor.clearFields();
// Store measured value into point
sensor.addField("VOC_Sensor", a0);
sensor.addField("VOC_PPM", PPM);
//sensor.addField("VOC_RS", R_S);
//sensor.addField("VOC_ALCOHOL", PPM_ALCOHOL);
/****************************** Self inclusions -> Not from InfluxDB ******************************/
Serial.print("Sensor Voltage: ");
Serial.print(v_o); //VOC concentration
Serial.println(" V"); //units
Serial.print("VOC Concentration calculation in arduino: ");
Serial.print(PPM); //VOC concentration
Serial.println(" PPM"); //units
Serial.print("Raw signal: ");
Serial.print(a0); //VOC concentration
Serial.println(" "); //units
delay(1000);
/***************************************************************************************************/
// Print what are we exactly writing
Serial.println(WiFi.localIP());
Serial.println("Line 286");
Serial.println(sensor.toLineProtocol());
// Write point
if (client.writePoint(sensor)) {
Serial.println("InfluxDB write successful");
} else {
Serial.print("InfluxDB write failed: ");
Serial.println(client.getLastErrorMessage());
}
Serial.println("Wait 200ms");
delay(200);
} //delete if void loop() line is deleted
The serial output displays
Connected to ssid
ACCESS UPDATES AT: ESP32_IP_ADDRESS
and then continues to display the "InfluxDB write successful" message with each data point.

ESP NOW failing using WIFI_AP_STA and WiFi.begin but working without the WiFi.begin

I am using code derived from Rui Santos https://RandomNerdTutorials.com/esp-now-esp32-arduino-ide/
I am using ESP NOW to send readings from an ESP32 sender to an ESP32 receiver then using the ESP32 receiver to send an html message to a ESP32 web server. Per Rui's instructions I need to start WiFi with WIFI_AP_STA to allow both wifi connection methods.
The sender and receiver code is below.
If I run the code as is, i.e. the receiver setup as WIFI_AP_STA but with the WiFi.begin line commented out, I get a sender status of:
Send success, and a receive status of:Receive status. SO there is no problem sending an ESP NOW message from the sender to the receiver (also works with WIFI_STA).
If I use WIFI_AP_STA and uncomment the line in the receiver "WiFi.begin(SSIS, PASSWORD)" so that I can send a message to the ESP32 web server, I get a send status of:Send fail, and a receive status of:Receive status with failed send. The send fails but the receive is still successful. Same fail if I use WIFI_AP. It seems that in WIFI_AP_STA mode with a WiFi.begin, the receiver sends an incorrect status back to the sender.
In summary, on the receiver, using wifi mode WIFI_AP_STA without a WiFi.begin, works for sending an ESP NOW message from sender to receiver, as it should.
Using wifi mode WIFI_AP_STA and WiFi.begin on the receiver, the sender fails when sending an ESP NOW message. When I implement the web code the web html message send works. However the issue can be reproduced using the simplified code below.
Using WiFi#2.0.0.
I've run out of ideas, is anyone able to point me at further investigation areas?
My sender code is:
#include <Arduino.h>
#include <WiFi.h>
#include <esp_now.h>
// Rui Santos https://RandomNerdTutorials.com/esp-now-esp32-arduino-ide/
uint8_t broadcastAddress[] = {0x24, 0x6F, 0x28, 0xAA, 0x84, 0x10};
typedef struct struct_message
{
char ESP32NowText[33];
} struct_message;
struct_message ESP32NowMessage;
//
String text = "AAA000010000200003000040000500006";
esp_now_peer_info_t peerInfo;
// callback when data is sent
void OnDataSent(const uint8_t *mac_addr, esp_now_send_status_t status)
{
Serial.print("\r\nLast Packet Send Status:\t");
Serial.println(status == ESP_NOW_SEND_SUCCESS ? "Delivery Success" : "Delivery Fail");
}
void setup()
{
Serial.begin(115200);
WiFi.mode(WIFI_STA);
if (esp_now_init() != ESP_OK)
{
Serial.println("Error initializing ESP-NOW");
return;
}
esp_now_register_send_cb(OnDataSent);
// Register peer
memcpy(peerInfo.peer_addr, broadcastAddress, 6);
peerInfo.channel = 0;
peerInfo.encrypt = false;
// Add peer
if (esp_now_add_peer(&peerInfo) != ESP_OK)
{
Serial.println("Failed to add peer");
return;
}
}
void loop()
{
strncpy(ESP32NowMessage.ESP32NowText, text.c_str(), text.length());
Serial.println("Msg to send:" + String(ESP32NowMessage.ESP32NowText));
Serial.println("Snd Len:" + String(sizeof(ESP32NowMessage)));
// Send message via ESP-NOW
esp_err_t result = esp_now_send(broadcastAddress, (uint8_t *)&ESP32NowMessage, sizeof(ESP32NowMessage));
if (result == ESP_OK)
{
Serial.println("Sent with success");
}
else
{
Serial.println("Error sending the data");
}
delay(2000);
}
My receiver code is:
#include <Arduino.h>
#include <WiFi.h>
#include <esp_now.h>
// Rui Santos https://RandomNerdTutorials.com/esp-now-esp32-arduino-ide/
typedef struct struct_message
{
char ESP32NowValues[33];
} struct_message;
struct_message ESP32NowMessage;
// callback function that will be executed when data is received
void OnDataRecv(const uint8_t *mac, const uint8_t *incomingData, int len)
{
memcpy(&ESP32NowMessage, incomingData, sizeof(ESP32NowMessage));
Serial.println("Bytes received: " + String(len));
Serial.println("Values:" + String(ESP32NowMessage.ESP32NowValues));
Serial.println("---------------------------------------");
}
const char WiFiSSID[] = "SSID";
const char WiFiPassword[] = "PASSWORD";
//
void setup()
{
Serial.begin(115200);
WiFi.mode(WIFI_AP_STA);
// WiFi.begin(WiFiSSID, WiFiPassword);
// Init ESP-NOW
if (esp_now_init() != ESP_OK)
{
Serial.println("Error initializing ESP-NOW");
return;
}
esp_now_register_recv_cb(OnDataRecv);
}
void loop()
{
}

Arduino's serial communication with gsm board

I am trying to write a program where arduino receives text from the gsm module.But my program is able to read the first text and perform a duty,but i want it to receive multiple texts and perform individual tasks for each respective texts?Any help will be great.Thank You.
#include <SoftwareSerial.h>
SoftwareSerial gsm(2, 3);
String inString[64]; // string to hold input coming from device
String read;
int count = 0;
boolean verifyingDone = false; // flags to determine the action completed and to perform next action
boolean regist = false;
boolean registercomplete = false;
boolean location = false;
void setup()
{
// put your setup code here, to run once:
Serial.begin(9600);
gsm.begin(4800);
delay(100);
gsm.print("ate0\r"); // removes the echo from the device
delay(100);
gsm.print("at+cnmi=1,2,0,0,0\r"); // to receive a text
Serial.print("The Device has been Intiated");
}
void loop() {
if (gsm.available())
{
while (gsm.available())
{
read = gsm.readString();
verifyNum(); // verifying the number
/* verifyingDone=true;
if(verifyingDone){
delay(1000);
gsm.print("at+cgpsinfo\r");
delay(1000);
checkGps();
verifyingDone=false;
*/
reading1: inString[count++] = read;
Serial.print(String(read));
if (count == 64) {
break;
}
}
delay(200);
count = 0;
}
}
void clearBufferArray()
{
for (int i = 0; i < count; i++)
{
inString[i] = "";
}
}
void verifyNum() {
if (read.startsWith("\r\n+CMT: ")) { // checking the incoming text and verifying the pre-defined number
int index1 = read.indexOf('"');
int index2 = read.indexOf('"', index1 + 1);
String Number = read.substring(index1 + 2, index2);
char floatbuf[100]; // make this at least big enough for the whole string
Number.toCharArray(floatbuf, 100);
int number = atoi(floatbuf);
//Serial.println(number);
delay(1000);
if (strcmp(number, 24190) == 0)
{
Serial.println("The Sending number is " + Number);
Serial.println("This is the registered number");
regist = true;
if (regist) {
gsm.print("AT+CMGS=\"0434519166\"\r"); // Sending registeration confirmation via sms
delay(100);
gsm.print("Success this mobile number has been registered .\r");
gsm.print("\r");
delay(100);
gsm.println((char)26);
delay(10000);
registercomplete = true;
if (regist == true && registercomplete == true) { //after complete registeration ,checking the gps and sending the co-ordinates
checkGps();
delay(500);
}
}
else {
gsm.print("AT+CMGSO=\"0434519166\" \,\"Someone tried to access your device\"\r"); // When not a registered number
}
}
}
}
void checkGps()
{
Serial.print("Gps Search has started");
delay(10000);//big delay to complete previous process //Not able to do this process completely------>Coz not able to re-read the string obtained from the first read..have to find an alternate to read incoming signals efficiently and re-using it
clearBufferArray();
delay(1000);
gsm.write("at+cgpsinfo\r");
delay(10000);
Serial.println();
Serial.println();
Serial.print("Locating.....Wait for a moment");
/*int spacePosition = read.indexOf(':');
if (read.charAt(spacePosition + 1) == ',' && regist==true )*/
if (read.startsWith("\r\n+CGPINFO:,,,"))
{
Serial.println("GPS signal not found.Go outside"); //
gsm.print("AT+CMGS=\"0434519166\"\r"); // Sending location as sms
delay(100);
gsm.print("GPS signal not found.Go outside ");
gsm.print("\r");
delay(100);
gsm.println((char)26);
delay(1000);
regist = false;
}
else
{
Serial.println("Signal found");
gsm.print("AT+CMGS=\"0434519166\"\r"); //Confirming signal found and sending location----->location finding programs can be obtained from previouses sketches
delay(100);
gsm.print("GPS found.Location will be sent soon ");
gsm.print("\r");
delay(100);
gsm.println((char)26);
delay(1000);
}
}
Thank You,Above code is justa tryout ,any help is welcome!

Arduino UNO WIFI not working properly

I have purchased an Arduino UNO WIFI board (http://www.arduino.org/products/boards/arduino-uno-wifi) but cannot get it work.
If it try the following example from http://www.arduino.org/learning/tutorials/boards-tutorials/restserver-and-restclient
the answer to every GET request e.g. arduino.local/arduino/analog/2
is "~". Within the Wifi-Console i find only strange chars like "�~�~�" and in the debug log i find:
746211> ARDUINO REST content: /arduino/digital/13/1
788705> ARDUINO REST content: /arduino/analog/2
I updated the firmware to 2016-03-18 - 79f152c, but no changes.
RestServer Code:
/*
RestServer.ino
Arduino Uno WiFi Ciao example
This example for the Arduino Uno WiFi shows how to use the
Ciao library to access the digital and analog pins
on the board through REST calls. It demonstrates how
you can create your own API when using REST style
calls through the browser.
Possible commands created in this shetch:
* "/arduino/digital/13" -> digitalRead(13)
* "/arduino/digital/13/1" -> digitalWrite(13, HIGH)
* "/arduino/analog/2/123" -> analogWrite(2, 123)
* "/arduino/analog/2" -> analogRead(2)
* "/arduino/mode/13/input" -> pinMode(13, INPUT)
* "/arduino/mode/13/output" -> pinMode(13, OUTPUT)
This example code is part of the public domain
http://www.arduino.org/learning/tutorials/restserver-and-restclient
*/
#include <Wire.h>
#include <ArduinoWiFi.h>
void setup() {
Wifi.begin();
Wifi.println("REST Server is up");
}
void loop() {
while(Wifi.available()){
process(Wifi);
}
delay(50);
}
void process(WifiData client) {
// read the command
String command = client.readStringUntil('/');
// is "digital" command?
if (command == "digital") {
digitalCommand(client);
}
// is "analog" command?
if (command == "analog") {
analogCommand(client);
}
// is "mode" command?
if (command == "mode") {
modeCommand(client);
}
}
void digitalCommand(WifiData client) {
int pin, value;
// Read pin number
pin = client.parseInt();
// If the next character is a '/' it means we have an URL
// with a value like: "/digital/13/1"
if (client.read() == '/') {
value = client.parseInt();
digitalWrite(pin, value);
}
else {
value = digitalRead(pin);
}
// Send feedback to client
client.println("Status: 200 OK\n");
client.print(F("Pin D"));
client.print(pin);
client.print(F(" set to "));
client.println(value);
client.print(EOL); //char terminator
}
void analogCommand(WifiData client) {
int pin, value;
// Read pin number
pin = client.parseInt();
// If the next character is a '/' it means we have an URL
// with a value like: "/analog/5/120"
if (client.read() == '/') {
// Read value and execute command
value = client.parseInt();
analogWrite(pin, value);
// Send feedback to client
client.println("Status: 200 OK\n");
client.print(F("Pin D"));
client.print(pin);
client.print(F(" set to analog "));
client.println(value);
client.print(EOL); //char terminator
}
else {
// Read analog pin
value = analogRead(pin);
// Send feedback to client
client.println("Status: 200 OK\n");
client.print(F("Pin A"));
client.print(pin);
client.print(F(" reads analog "));
client.println(value);
client.print(EOL); //char terminator
}
}
void modeCommand(WifiData client) {
int pin;
// Read pin number
pin = client.parseInt();
// If the next character is not a '/' we have a malformed URL
if (client.read() != '/') {
client.println(F("error"));
client.print(EOL); //char terminator
return;
}
String mode = client.readStringUntil('\r');
if (mode == "input") {
pinMode(pin, INPUT);
// Send feedback to client
client.println("Status: 200 OK\n");
client.print(F("Pin D"));
client.print(pin);
client.println(F(" configured as INPUT!"));
client.print(EOL); //char terminator
return;
}
if (mode == "output") {
pinMode(pin, OUTPUT);
// Send feedback to client
client.println("Status: 200 OK\n");
client.print(F("Pin D"));
client.print(pin);
client.println(F(" configured as OUTPUT!"));
client.print(EOL); //char terminator
return;
}
client.print(F("error: invalid mode "));
client.println(mode);
client.print(EOL); //char terminator
}
The solution is to enable "Enable SLIP on serial port" in the SLIP section of the "Connectivity" Tab in the arduino web control.

XBee printout, void setup()

I'm having trouble with my XBee's printing out to the monitor a simple statement, within the void setup(), as shown in my program below.
It prints the GPS and various sensor data, but it skips the whole introductory sentences. Whenever I open the arduino serial monitor, with the board plugged into my computer, it works fine.
Any suggestions? I'm at a lost!
Thanks :)
// Temperature Sensor data, Air Quality, and GPS data update XBEE
//CSV format for user interpretation
//Last updated 11/5/14
//Amy Laguna
#include <Adafruit_GPS.h>
#include <math.h>
#include <SoftwareSerial.h>
SoftwareSerial XBee(2, 3);
SoftwareSerial mySerial(8, 7);
//Read temperature sensor on A1
int tempPin = 1;
//Read CO sensor on A0
int coPin = 0;
//Read Oxygen sensor on A2
int opin = 2;
//GPS setup
Adafruit_GPS GPS(&mySerial);
//Use to debug
//SET to 'fale' to turn off echoing the GPS data to Serial
//Set to 'true' to debug and listen to raw GPS data
#define GPSECHO false
// this keeps track of whether we're using the interrupt
boolean usingInterrupt = false;
void useInterrupt(boolean);
void setup()
{
// connect at 115200 so we can read the GPS fast enough and echo without dropping chars
XBee.begin(115200);
Serial.begin(115200);
delay(5000);
XBee.println("Vehicle GPS, Temperature, and Air Quality Data!");
delay(2000);
XBee.println("Note: Elevation in Pensacola Florida: ~ 31 m (102 ft)");
XBee.println();
XBee.println("\n Date: Time: Fix: Location: Speed (mph): Elevation: CO: O2: Temperature: ");
// 9600 NMEA is the default baud rate for Adafruit MTK GPS's
GPS.begin(9600);
// RMC (recommended minimum) and GGA (fix data) including altitude
GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
// Set the update rate
GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ); // 1 Hz update rate
// For the parsing code to work nicely and have time to sort thru the data, and
// print it out we don't suggest using anything higher than 1 Hz
useInterrupt(true);
delay(1500);
}
// Interrupt is called once a millisecond, looks for any new GPS data, and stores it
SIGNAL(TIMER0_COMPA_vect) {
char c = GPS.read();
// if you want to debug, this is a good time to do it!
#ifdef UDR0
if (GPSECHO)
if (c) UDR0 = c;
#endif
}
void useInterrupt(boolean v) {
if (v) {
// Timer0 is already used for millis() - we'll just interrupt somewhere
// in the middle and call the "Compare A" function above
OCR0A = 0xAF;
TIMSK0 |= _BV(OCIE0A);
usingInterrupt = true;
} else {
// do not call the interrupt function COMPA anymore
TIMSK0 &= ~_BV(OCIE0A);
usingInterrupt = false;
}
}
uint32_t timer = millis();
void loop() // run over and over again
{
if (! usingInterrupt) {
// read data from the GPS in the 'main loop'
char c = GPS.read();
// if you want to debug, this is a good time to do it!
if (GPSECHO)
if (c) XBee.print(c);
}
// if a sentence is received, we can check the checksum, parse it...
if (GPS.newNMEAreceived()) {
if (!GPS.parse(GPS.lastNMEA())) // this also sets the newNMEAreceived() flag to false
return; // we can fail to parse a sentence in which case we should just wait for another
}
// if millis() or timer wraps around, we'll just reset it
if (timer > millis()) timer = millis();
// approximately every 2 seconds or so, print out the current stats
if (millis() - timer > 2000) {
timer = millis(); // reset the timer
PrintGPS(); //Print GPS readings
PrintAirQuality(); //Print CO and Temperature readings
}
}
void PrintGPS()
{
//Print Date, Time, Fix
XBee.print("\n");
XBee.print(GPS.month, DEC); XBee.print('/');
XBee.print(GPS.day, DEC); XBee.print("/20");
XBee.print(GPS.year, DEC);
XBee.print(" , ");
XBee.print(GPS.hour, DEC); XBee.print(':');
XBee.print(GPS.minute, DEC); XBee.print(':');
XBee.print(GPS.seconds, DEC);
}
Maybe try a longer delay before the XBee.println() statements. If the radio modules haven't associated yet, they won't be ready for you to start sending data through them.
Alternatively, wait until the first call to PrintGPS() and send it then:
void PrintGPS()
{
static int first_time = 1;
if (first_time) {
print_headers();
first_time = 0;
}
//Print Date, Time, Fix
...

Resources