Send variations of text


#1

Hello, I ask for support to solve a problem, where I have a sensor SEN-08942 (https://air.imag.fr/index.php/SEN-08942). and I need to send the address data to thinger.io and they are texts I am using the following code and only send me the fixed number 26 using the text / value widget

this is the code I am using:

#define DEBUG
#define DISABLE_TLS

#include <BridgeSSLClient.h>
#include <ThingerYun.h>

#define USERNAME “xxx”
#define DEVICE_ID “xxx”
#define DEVICE_CREDENTIAL “xxxx”
#define uint unsigned int
#define ulong unsigned long

#define PIN_ANEMOMETER 1 // Digital 2
#define PIN_RAINGAUGE 3 // Digital 3
#define PIN_VANE A5 // Analog 5
int datos;
ThingerYun thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL);
// How often we want to calculate wind speed or direction
#define MSECS_CALC_WIND_SPEED 5000
#define MSECS_CALC_WIND_DIR 5000
#define MSECS_CALC_RAIN_FALL 30000

volatile int numRevsAnemometer = 0; // Incremented in the interrupt
volatile int numDropsRainGauge = 0; // Incremented in the interrupt
ulong nextCalcSpeed; // When we next calc the wind speed
ulong nextCalcDir; // When we next calc the direction
ulong nextCalcRain; // When we next calc the rain drop
ulong time; // Millis() at each start of loop().
//int viento;
// ADC readings:
#define NUMDIRS 8
ulong adc[NUMDIRS] = {26, 45, 77, 118, 161, 196, 220, 256};

// These directions match 1-for-1 with the values in adc, but
// will have to be adjusted as noted above. Modify ‘dirOffset’
// to which direction is ‘away’ (it’s West here).
char *strVals[NUMDIRS] = {“W”,“NW”,“N”,“SW”,“NE”,“S”,“SE”,“E”};
byte dirOffset=0;

//=======================================================
// Initialize
//=======================================================
void setup() {

Serial.begin(115200);
Bridge.begin();
pinMode(PIN_ANEMOMETER, INPUT);
digitalWrite(PIN_ANEMOMETER, HIGH);
digitalWrite(PIN_RAINGAUGE, HIGH);
attachInterrupt(0, countAnemometer, FALLING);
attachInterrupt(1, countRainGauge, FALLING);
nextCalcRain = millis() + MSECS_CALC_RAIN_FALL;
nextCalcSpeed = millis() + MSECS_CALC_WIND_SPEED;
nextCalcDir = millis() + MSECS_CALC_WIND_DIR;

thing[“millis”] >> outputValue(millis());
thing[“dato”] >> [](pson& out){
out[“datos”] =numRevsAnemometer;
thing[“mention”] >> [](pson& in){
const char user =*strVals[NUMDIRS];

// out[“hum”] =DHT.humidity;
// int chk = DHT.read21(DHT21_PIN);
// Serial.print(hum);
//Serial.print(temp);
delay(2000);
};
};
}

//=======================================================
// Main loop.
//=======================================================
void loop() {
thing.handle();
time = millis();

if (time >= nextCalcSpeed) {
calcWindSpeed();
nextCalcSpeed = time + MSECS_CALC_WIND_SPEED;
}
if (time >= nextCalcDir) {
calcWindDir();
nextCalcDir = time + MSECS_CALC_WIND_DIR;
}
if (time >= nextCalcRain) {
calcRainFall();
nextCalcRain = time + MSECS_CALC_RAIN_FALL;
}

}

//=======================================================
// Interrupt handler for anemometer. Called each time the reed
// switch triggers (one revolution).
//=======================================================
void countAnemometer() {
numRevsAnemometer++;
}

//=======================================================
// Interrupt handler for rain gauge. Called each time the reed
// switch triggers (one drop).
//=======================================================
void countRainGauge() {
numDropsRainGauge++;
}

//=======================================================
// Find vane direction.
//=======================================================
void calcWindDir() {
int val;
byte x, reading;

val = analogRead(PIN_VANE);
val >>=2; // Shift to 255 range
reading = val;

// Look the reading up in directions table. Find the first value
// that’s >= to what we got.
for (x=0; x<NUMDIRS; x++) {
if (adc[x] >= reading)
break;
}
//Serial.println(reading, DEC);
x = (x + dirOffset) % 8; // Adjust for orientation
Serial.print(" Dir: ");
Serial.println(strVals[x]);
}

//=======================================================
// Calculate the wind speed, and display it (or log it, whatever).
// 1 rev/sec = 1.492 mph = 2.40114125 kph
//=======================================================
void calcWindSpeed() {
int x, iSpeed;
int viento;
// This will produce kph * 10
// (didn’t calc right when done as one statement)
long speed = 24011;
speed *= numRevsAnemometer;
speed /= MSECS_CALC_WIND_SPEED;
iSpeed = speed; // Need this for formatting below

Serial.print("Wind speed: ");
x = iSpeed / 10;
Serial.print(x);
Serial.print(’.’);
x = iSpeed % 10;
viento= Serial.print(x);

numRevsAnemometer = 0; // Reset counter
}

//=======================================================
// Calculate the rain , and display it (or log it, whatever).
// 1 bucket = 0.2794 mm
//=======================================================
void calcRainFall() {
int x, iVol;
// This will produce mm * 10000
// (didn’t calc right when done as one statement)
long vol = 2794; // 0.2794 mm
vol *= numDropsRainGauge;
vol /= MSECS_CALC_RAIN_FALL;
iVol = vol; // Need this for formatting below

Serial.print("Rain fall: ");
x = iVol / 10000;
Serial.print(x);
Serial.print(’.’);
x = iVol % 10000;
Serial.print(x);
Serial.println();

numDropsRainGauge = 0; // Reset counter
thing.handle();
}

the speed data I can read correctly my problem is the directions.

I hope you can help me.