Sketch works/ Now how to I send my strings and analog values to gateway?

Started by djash40, December 11, 2015, 02:48:59 PM

djash40

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.

Felix

Have you seen the examples?
Plenty there to show you how to send data in many different ways.

djash40

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?


syrinxtech

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.


djash40

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

djash40

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... :)

djash40

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?

Felix

See this reference.
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)

djash40

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.


djash40

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.

Felix

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).