Hi,
1.
In the same code (I modified a bit again) I want to get readings of GPS. Since I don't have much programming experience and also that I am new to waspmote, I am not able to plug-in GPS functions properly. If you can help then I would be thankful.
Code:
char* sinkMAC = "0013A200406A6225 "; // gateway mac
char* selfMAC = "0013A200406A62BC "; //node mac
int8_t state=0;
int g=0;
uint8_t pkt_id = 0;
long previous=0;
int GPS_Error = 1;
packetXBee* paq_sent;
char* msg = "1";
const char* sep ="@@";
void floatToStr(char* retStr,float value)
{
int int_part = (int)value;
value = value-(float)int_part;
value = value*1000;
int decimal_part = (int)value;
sprintf(retStr,"%d.%d",int_part,decimal_part);
XBee.println(retStr);
}
void getFormattedVals(char* formattedData,float atp, float CO, float VOC, float NO2)
{
int int_part,decimal_part;
char atpStr[6],coStr[6],vocStr[6],no2Str[6];
floatToStr(atpStr,atp);
sprintf(formattedData,"%s%s",atpStr,sep);
XBee.println(formattedData);
}
void getSensorValues(char* dataTemp)
{
int GPS_Error=1;
int GPS_Tries=0;
//char GPSData[40];
char sensorData[40];
SensorGas.configureSensor(SENS_SOCKET3A, 1, 1);
SensorGas.setSensorMode(SENS_ON, SENS_SOCKET3A);
SensorGas.configureSensor(SENS_SOCKET2A,1,1);
SensorGas.setSensorMode(SENS_ON, SENS_SOCKET2A);
delay(30000);
SensorGas.configureSensor(SENS_SOCKET2B, 1, 1);
SensorGas.setSensorMode(SENS_ON, SENS_SOCKET2B);
delay(30000);
XBee.println("Sending Temperature");
int temperature_value=RTC.getTemperature();
XBee.println(temperature_value);
XBee.println("Sending atmospheric pressure");
float atp_value=SensorGas.readValue(SENS_PRESSURE);
SensorGas.setSensorMode(SENS_OFF, SENS_PRESSURE);
XBee.println(atp_value);
// Printing a message, remember to open 'Serial Monitor' to be able to see this message
XBee.println("Sending CO sensor data after 30 seconds");
float CO_value = SensorGas.readValue(SENS_SOCKET3A);
SensorGas.setSensorMode(SENS_OFF, SENS_SOCKET3A);
XBee.println(CO_value);
XBee.println("Sending VOC sensor data after 30 seconds");
float VOC_value = SensorGas.readValue(SENS_SOCKET2A);
SensorGas.setSensorMode(SENS_OFF, SENS_SOCKET2A);
XBee.println(VOC_value);
XBee.println("Sending NO2 sensor data after 30 seconds");
float NO2_value = SensorGas.readValue(SENS_SOCKET2B);
SensorGas.setSensorMode(SENS_OFF, SENS_SOCKET2B);
XBee.println(NO2_value);
getFormattedVals(sensorData,atp_value,CO_value,VOC_value,NO2_value);
XBee.println(sensorData);
sprintf(dataTemp,"%d%s%d%s%s",GPS_Error,sep,temperature_value,sep,sensorData);
XBee.print("Msg from getValueSensors: ");
XBee.println(dataTemp);
}
void setup()
{
SensorGas.setBoardMode(SENS_ON);
// set GPS on
GPS.setMode(GPS_ON);
XBee.println("Start WASP Deployment");
// Inits the XBee 802.15.4 library
xbee802.init(XBEE_802_15_4,FREQ2_4G,NORMAL);
// Powers XBee
xbee802.ON();
//xbee802.setPowerLevel(0); //ideally 0=50m and 4=500m
XBee.flush();
}
void loop()
{
// Adding data to the packet to be sent
XBee.println("");
XBee.println("COLLECT_SENSOR_DATA ");
pkt_id = pkt_id+1;
char dataTemp[50];
char data[90];
getSensorValues(dataTemp);
sprintf(data,"%s%s%s",msg,sep,dataTemp);
XBee.println(data);
// Set params to send
paq_sent=(packetXBee*) calloc(1,sizeof(packetXBee));
paq_sent->mode=UNICAST;
paq_sent->address_type= 0;
paq_sent->MY_known = 0;
paq_sent->opt=0;
paq_sent->packetID=pkt_id;
xbee802.setOriginParams(paq_sent, selfMAC, MAC_TYPE);
xbee802.setDestinationParams(paq_sent, sinkMAC, data, MAC_TYPE, DATA_ABSOLUTE);
xbee802.sendXBee(paq_sent);
if( !xbee802.error_TX )
{
XBee.println("ok");
}
free(paq_sent);
paq_sent=NULL;
xbee802.pos--;
delay(1000);
XBee.println("FLUSHING NOW !!");
XBee.flush();
XBee.println("FLUSHED !!");
}
2. Apart from this code I am also trying an another code for the same purpose. Here I have managed to use GPS functions properly (Not getting compilation error) and also that GPS starts to initialize but it doesn't work. I see "Setting up GPS..." message and it hangs afterwards.
Another problem with this code is that I don't get any output on wifi whereas USB works well.
Code:
void setup()
{
// Inits the XBee 802.15.4 library
//USB.begin();
SensorGas.setBoardMode(SENS_ON);
SensorGas.configureSensor(SENS_SOCKET2A,1,1);
SensorGas.setSensorMode(SENS_ON, SENS_SOCKET2A);
SensorGas.setBoardMode(SENS_ON);
SensorGas.configureSensor(SENS_SOCKET2B, 4, 2);
SensorGas.setSensorMode(SENS_ON, SENS_SOCKET2B);
SensorGas.setBoardMode(SENS_ON);
SensorGas.configureSensor(SENS_SOCKET3A,2,3);
}
void loop()
{
xbee802.init(XBEE_802_15_4,FREQ2_4G,NORMAL);
// Powers XBee
xbee802.ON();
XBee.println("The Concentration of CH4 Gas measured is equal to:");
delay(30000);
float val_1 = SensorGas.readValue(SENS_SOCKET2A);
XBee.println(val_1);
XBee.println("The Concentration of No2 Gas measured is equal to:");
delay(30000);
float val_2 = SensorGas.readValue(SENS_SOCKET2B);
XBee.println(val_2);
XBee.println("The Concentration of CO Gas measured is equal to:");
delay(30000);
float val_3 = SensorGas.readValue(SENS_SOCKET3A);
XBee.println(val_3);
XBee.println("Setting up GPS...");
GPS.ON();
// waiting for GPS is connected to satellites
while( !GPS.check() ) delay(1000);
XBee.println("Connected");
GPS.getPosition();
XBee.println("---------------");
XBee.print("Time: ");
XBee.println(GPS.timeGPS);
XBee.print("Date: ");
XBee.println(GPS.dateGPS);
XBee.print("Latitude: ");
XBee.println(GPS.latitude);
XBee.print("Longitude: ");
XBee.println(GPS.longitude);
XBee.print("Altitude: ");
XBee.println(GPS.altitude);
XBee.print("Speed: ");
XBee.println(GPS.speed);
XBee.print("Course: ");
XBee.println(GPS.course);
XBee.println("---------------");
packetXBee* paq_sent;
int8_t state=0;
long previous=0;
char data[90];
sprintf(data,"%s%s%s%s%s%s%s",val_1,val_2,val_3,GPS.timeGPS,GPS.dateGPS,GPS.latitude,GPS.longitude,GPS.altitude,GPS.speed,GPS.course);
XBee.println(data);
// Set params to send
paq_sent=(packetXBee*) calloc(1,sizeof(packetXBee));
paq_sent->mode=UNICAST;
paq_sent->MY_known=0;
paq_sent->packetID=0x52;
paq_sent->opt=0;
xbee802.hops=0;
xbee802.setOriginParams(paq_sent, "0013A200406A62BC", MAC_TYPE);
xbee802.setDestinationParams(paq_sent, "0013A200406A6225", data, MAC_TYPE, DATA_ABSOLUTE);
state=xbee802.sendXBee(paq_sent);
if(state==0)
{
XBee.println("ok");
}
free(paq_sent);
paq_sent=NULL;
delay (5000);
}
3. I tried to edit AP = 0 but I am getting library error when I run my codes. If you can then please email me the modified WaspXbeeCore.cpp file.
zeus2kx@gmail.comSorry for this mess but I must understand how to use it properly before I enjoy working with your device.
Thanks.
Best,