LowPowerLab Forum

Software support => Pi Gateway => Topic started by: djash40 on December 11, 2015, 02:48:59 PM

Title: Sketch works/ Now how to I send my strings and analog values to gateway?
Post by: djash40 on December 11, 2015, 02:48:59 PM
ok, my sketch works in all is well however, I'm not really sure how to send variable data from analog variable and text data similar to serial.print and serial.print line over the radio. Can someone point me in the right direction show me a tutorial on how to accomplish this? I ultimately would like to use mqtt on the gateway. However just getting the values to the gateway would be and accomplishment.
I'll attach the sketch.
Title: Re: Sketch works/ Now how to I send my strings and analog values to gateway?
Post by: Felix on December 11, 2015, 02:58:06 PM
Have you seen the examples (https://github.com/LowPowerLab/RFM69/tree/master/Examples)?
Plenty there to show you how to send data in many different ways.
Title: Re: Sketch works/ Now how to I send my strings and analog values to gateway?
Post by: djash40 on December 11, 2015, 03:10:34 PM
yes I looked at the WeatherNode one to see how you send the temp. But as an inexperienced novice I am unable to comprehend what I'm looking at.
I just need to send a few things.
It looks like your send in one string?
sprintf(buffer, "BAT:%sv F:%d H:%d P:%s", BATstr, weatherShield_SI7021.getFahrenheitHundredths(), weatherShield_SI7021.getHumidityPercent(),
I cannot tell how to do it. Could someone break it down?
Can the radio code go somewhere on top or bottom and then be called similar to serial.print?
Title: Re: Sketch works/ Now how to I send my strings and analog values to gateway?
Post by: Sergegsx on December 11, 2015, 05:51:04 PM
check this tutorial...
https://liudr.wordpress.com/2012/01/16/sprintf/
Title: Re: Sketch works/ Now how to I send my strings and analog values to gateway?
Post by: syrinxtech on December 11, 2015, 05:51:36 PM
Quote from: djash40 on December 11, 2015, 03:10:34 PM
yes I looked at the WeatherNode one to see how you send the temp. But as an inexperienced novice I am unable to comprehend what I'm looking at.
I just need to send a few things.
It looks like your send in one string?
sprintf(buffer, "BAT:%sv F:%d H:%d P:%s", BATstr, weatherShield_SI7021.getFahrenheitHundredths(), weatherShield_SI7021.getHumidityPercent(),
I cannot tell how to do it. Could someone break it down?
Can the radio code go somewhere on top or bottom and then be called similar to serial.print?

djash40,

The sprintf() function is designed to take text and variables and assign them to a character buffer, usually for printing.  In the code above, the variable "buffer" is used to hold the concatenation of everything in quotes.  The "%s" holds string (char[]) data and the "%d" is used to hold integer data.  So, you can break down the line of code above as follows:

"BAT:%sv F:%d H:%d P:%s", BATstr, weatherShield_SI7021.getFahrenheitHundredths(), weatherShield_SI7021.getHumidityPercent()

The first %sv gets replaced by the contents of the variable BATstr
The first %d gets replaced by the contents of the function weatherShield_SI7021.getFahrenheitHundredths()
The second %d gets replaced by the contents of the function weatherShield_SI7021.getHumidityPercent()
The last %s should probably be a %d and would contain the function designed to return the barometric pressure.

When you're done the variable "buffer" can be sent over the wire and contain the contents all 3 variables.

Title: Re: Sketch works/ Now how to I send my strings and analog values to gateway?
Post by: djash40 on December 16, 2015, 05:48:44 PM
How do I get the data from my pin 7?
I tried this:
// ########### Test send #################
  delay(250);
byte buffLen=sprintf(buff, "coolbeansflow/%d Pin 7 is: %s ", flow, (digitalRead(reload)));
if (radio.sendWithRetry(GATEWAYID, buff, buffLen))
   Serial.print(" ok!");
   //########## end test send #############
Title: Re: Sketch works/ Now how to I send my strings and analog values to gateway?
Post by: djash40 on December 16, 2015, 06:13:00 PM
This on the node:
  // ########### Test send #################
  delay(500);
byte buffLen=sprintf(buff, "flow/%d /test/%d /reset/%d /pump/%d", flow, digitalRead(test), digitalRead(reload), digitalRead(ssrgrnled));
if (radio.sendWithRetry(GATEWAYID, buff, buffLen))
   Serial.print(" ok!");
   //########## end test send #############

Produces this on the gateway:
flow/12 /test/1 /reset/1 /pump/0 - ACK sent


Progress... :)
Title: Re: Sketch works/ Now how to I send my strings and analog values to gateway?
Post by: djash40 on December 17, 2015, 05:18:08 PM
Ok here goes;
//############# Begin code for temperature #########################
sensors.requestTemperatures();
float s4 = sensors.getTempC(watertemp);
    if (s4 > 0)
  {
     //  djash  Serial.print("Sensor 4 temp is: ");
  printTemperature(watertemp);

  }

This prints the value to serial fine now I'm trying to send the temperature over the radio and no go with this:
if (timer0 > interval) {
    timer0 -= interval; //reset the timer
byte buffLen=sprintf(buff, "node/%d flow/%d /test/%d /reset/%d /pump/%d /wtemp/%f", NODEID, flow, digitalRead(test), digitalRead(reload), digitalRead(ssrgrnled), watertemp);
if (radio.sendWithRetry(GATEWAYID, buff, buffLen));


Other side see this:
node/2 flow/3 /test/1 /reset/1 /pump/1 /wtemp/? - ACK sent

tried %d %f %lf
Any ideas how to get my temperature over the radio?
Title: Re: Sketch works/ Now how to I send my strings and analog values to gateway?
Post by: Felix on December 17, 2015, 06:00:05 PM
See this reference (http://www.cplusplus.com/reference/cstdio/printf/).
Note that for floats you will need to use something like dtostrf() to format a float into a string.
For instance dtostrf(temperature, 3,2, myStringBuff)
Title: Re: Sketch works/ Now how to I send my strings and analog values to gateway?
Post by: djash40 on December 31, 2015, 03:48:39 PM
ok I'm back at it again.
i've searched for many examples for dtostrf and tried many but I keep getting error.
//#### code begin ######
tempsetup();
{
signed char pipetemp[7];
String tempValue = dtostrf(watertemp, 3, 2, pipetemp); // convert float to String, minimum size = 1, decimal places = 2
}
//#### code end #######

Errors below:
exit status 1
cannot convert 'uint8_t* {aka unsigned char*}' to 'double' for argument '1' to 'char* dtostrf(double, signed char, unsigned char, char*)'

Any ideas to get my temperature to a string? Anyone, please help.
Title: Re: Sketch works/ Now how to I send my strings and analog values to gateway?
Post by: Felix on December 31, 2015, 04:22:08 PM
See my numerous examples (https://github.com/LowPowerLab/RFM69/search?utf8=%E2%9C%93&q=dtostrf) of how to use dtostrf.
Title: Re: Sketch works/ Now how to I send my strings and analog values to gateway?
Post by: djash40 on December 31, 2015, 04:29:15 PM
ok, I used this:
//############# Begin code for temperature #########################
sensors.requestTemperatures();
float s4 = sensors.getTempC(watertemp);
    if (s4 > 0)
  {
    Serial.print("Sensor 4 temp is: ");
printTemperature(watertemp);
double watertemp;
watertemp = s4;
dtostrf(watertemp, 3, 2, pipetemp); // convert float to String

  }
//############ End code for temperature ##############################

This returns the temperature in the serial monitor in Fahrenheit in the serial monitor. Great however, over the radio I get Celsius with the code below:

  if (timer0 > interval) {
    timer0 -= interval; //reset the timer
byte buffLen=sprintf(buff, "node/%d flow/%d /test/%d /reset/%d /pump/%d /wtemp/%s", NODEID, flow, digitalRead(test), digitalRead(reload), digitalRead(ssrgrnled), pipetemp);
if (radio.sendWithRetry(GATEWAYID, buff, buffLen));

Help me I'm learning and struggling.
Title: Re: Sketch works/ Now how to I send my strings and analog values to gateway?
Post by: Felix on December 31, 2015, 04:57:12 PM
1. Please start wrapping your code with code tags.
2. Can you recap in a more short and to the point explanation what is not working or what you're trying to do.. code included but not code that we don't care about (ie cut the noise).