Advertisement
Alx09

Untitled

Jun 28th, 2023
920
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.77 KB | None | 0 0
  1. tatic char* getTelemetryPayload() {
  2.   Senzor s = utilizator.getSenzor();
  3.   int sensorValue = analogRead(A0);  // Read the sensor value
  4.                                      // Convertirea valorii analogice la tensiune
  5.   float voltage = sensorValue * (3.3 / 1023.0);
  6.   float temperatureC = (voltage - 0.5) * 25;  // Convert the voltage to temperature in Celsius
  7.   Serial.print("Temperature: ");
  8.   Serial.print(temperatureC);
  9.   Serial.println(" °C");
  10.   // Create the JSON payload using sprintf
  11.   sprintf((char*)telemetry_payload,
  12.           "{ \"SenzorId\": %d, \"Val1\": %.2f, \"Val2\": %.2f }",
  13.           s.getSenzorId(), temperatureC, (30 + (millis() % 10) / 10.0));
  14.  
  15.   telemetry_send_count++;
  16.   Serial.println((char*)telemetry_payload);
  17.  
  18.   return (char*)telemetry_payload;
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement