Go Down

Topic: Telit Modem/Cloud monitoring sevice Need help please ! (Read 82 times) previous topic - next topic

Frostedfocus

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.

Code: [Select]


#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
}
}
 }}}

PaulS

Code: [Select]
  float temperature =(sensors.getTempCByIndex(0));
(What's) (with) (the) (parentheses) (?)

Quote
this reading then gets placed into the buffer by using this -

dtostrf(temperature,2,0,buffer);
In a field width of 2, show the float with no decimal places... If you don't care about the decimal places, why not just make temperature an int, and forget about trying to deal with a float?

What size is buffer? What type?
Code: [Select]
char buffer[2];
Never mind. I see that it is the correct type but the wrong size. You can't write 2 characters and a terminating NULL in a two element array.

Quote
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:'
If you start storing the data only after the : arrives, you won't need to remove anything from the buffer.

Code: [Select]
  }}}
Its ONE curly brace per line. You wouldn't need so many here if you didn't { splatter { extra ones uselessly { in your code.

Code: [Select]
    if (telitSerial.available()) {
    Serial.write(telitSerial.read());

In one ear and out the other.

You can't tokenize data you haven't stored.

Code: [Select]
  char temp_Send[50];
  sprintf(temp_Send,"AT#DWSEND=0,property.publish,key,bat_temp,value,%s",buffer);

You can't store 48 characters plus a 2 character string plus a NULL terminator in a 50 element array.
The art of getting good answers lies in asking good questions.

Frostedfocus

Thanks for your advise but that is not what i asked, the code works fine for what i need to do with it right now, all i need to know is a way to tokenize the value that comes in with #DWRING: from the modem. because the Usual ways that i would use does not work like '.find() and strstr(). Al i would like to do is somehow strtok() the 'xx,xx,xx' value in 3 separate compartments. i am just struggling to pick up the correct buffer that has those values in it. Or maybe i have not created the correct buffer that stores the '#DWRING: xx,xx,xx' values in it.
''
  if(telitSerial.available()>0);{                   
char response[60];
for(int i = 0 ; telitSerial.available() > 0 && i<60 ; i++) {
   response = Serial.read();
   if(strstr(response, "#DWSEND:")){
   Serial.println(i);           ''

Dont mind this last part i was supposed to delete it because its not part of the code im using now.

PaulS

Quote
all i need to know is a way to tokenize the value that comes in with #DWRING: from the modem.
Without saving the data, you can NOT POSSIBLY PARSE IT.
The art of getting good answers lies in asking good questions.

Go Up