Good day everybody, i am hoping somebody here can help me out with a proper strtok() or strstr() example to use in my code,
I am busy writing software on an arduino Uno that connects to a telit GT-HE910 modem via use of a RS232 level converter, The units comunicates over Serial Uart and the comunication works very well, but my problem is this. After i have established a connection with the Telit devisewise cloud service i then read the temperature from a dallas DS18B20 temp sensor by using -
float temperature =(sensors.getTempCByIndex(0));
this reading then gets placed into the buffer by using this -
dtostrf(temperature,2,0,buffer);
and then gets sent of to the cloud like this -
sprintf(temp_Send,"AT#DWSEND=0,property.publish,key,bat_temp,value,%s",buffer);
After the cloud receives this sprintf string it then responds with an update code that looks like this -
' #DWRING: xx,xx,xx"
The "xx" being the numbers. lets say i read the temperature at 24 degrees celsius and i send the string, the cloud then sends a response back #DWRING: 5,4,2, where the 5 is my thing location,, the 4 is my temperature update, and the 2 is the position value update time squence. My problem is that when i receive the #DWRING: xx,xx,xx i need to take that string and place it into a buffer where i can then remove the '#DWRING:' and then split up the 'xx,xx,xx' so that i have value 1= xx, value 2=xx, and value3=xx. Then i can take value2 and place it into a new command with AT#DWRCV='xx',
Now i have tried everything i can think of to read the '#DWRING: xx,xx,xx' string that comes in from the modem but i just cant manage to read it correctly so i can split it upp with string splitter and utilize the numbers individualy,
I hope somebody here can help me, i have found many examples on how to use serial entries that you type into your serial response windows or serial entries that you place into your code with a const char () terms and they work very well in these methods, but the string i need to utlize and split up is not something i type in or program into my code, it is a serial UART response from the cloud/modem that is a type of float and will be diffrent numbers after every sprintf() response. can somebody please help me out, i dont know if i should maybe be using strstr() or strtok() or something like that, and if so how do i use it with a serial float response from the modem. i have added the code up to the point where i need to utilize the response. i have also added a screen shot of the serial monitor print out.
I hope this makes sense and sorry for the terrible spelling.
#include <SoftwareSerial.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <stdio.h>
#define ONE_WIRE_BUS A0
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
SoftwareSerial telitSerial(7, 6); // Connection to UART
String response; //global variable for pulling AT command responses from inside functions
#define TIMEOUT 3000 // Millis timer interval
char buffer1[10];
char buffer[2];
int val1 = " ";
void setup()
{
Serial.begin(9600);
{
Serial.println("Connection Status ?");
telitSerial.begin(9600);
telitSerial.println("Connection Active !");
delay(200);
{
setupMODEM();
}}}
void loop()
{
if (telitSerial.available()) {
Serial.write(telitSerial.read());
}
if (Serial.available()) {
telitSerial.write(Serial.read());
}
tempCommand();
}
void setupMODEM(void)
{
ModemCommand(F("AT"));
ModemCommand(F("AT+CGDCONT=1,\"IP\",\"internet\""));
ModemCommand(F("AT#SGACT=1,1"));
ModemCommand(F("AT#DWCFG=open-api.devicewise.com,0,6BMsKddas6Kq8KW4"));
ModemCommand(F("AT#DWCONN=1"));
}
void ModemCommand(String command)
{
telitSerial.println(command);
while (telitSerial.available() == 0); // wait for first char
unsigned long lastRead = millis(); // last time a char was available
while (millis() - lastRead < TIMEOUT){
while (telitSerial.available()){
Serial.write(telitSerial.read());
lastRead = millis(); // update the lastRead timestamp
}
}
}
void tempCommand()
{
sensors.begin();
sensors.requestTemperatures();
float temperature =(sensors.getTempCByIndex(0));
dtostrf(temperature,2,0,buffer);
char temp_Send[50];
sprintf(temp_Send,"AT#DWSEND=0,property.publish,key,bat_temp,value,%s",buffer);
ModemCommand(temp_Send);
delay(5000);
{
if(telitSerial.available()>0);{ // From here is where i am trying to use the #DWRING response
char response[60];
for(int i = 0 ; telitSerial.available() > 0 && i<60 ; i++) {
response[i] = Serial.read();
if(strstr(response, "#DWSEND:")){
Serial.println(i); // until here
}
}
}}}
