I have what is a weather station on a Wifi-1010; temperature, humidity, and a switch state. I view this data remotely on my smartphone using the LightBlue app. I want to post this data to the Arduino Cloud without adding more hardware. Is there a way to do this? It appears the LightBlue app can post the data to AWS or Azure, but I don' really want to use those services.
It looks like the hardware you have is compatible with the Arduino cloud, so it should be able to send data there. What code do you have running to provide weather station functionality?
Here is the code. It controls a SHT-22 temperature/humidity sensor, monitors the state of a hall effect sensor, and the battery voltage.
/*
Smart Shield (Temperature (Centigrade), Humidity (%), tamper detection (1=container is open), and battery monitor (%)) with BLE connectivity
*/
#include <ArduinoBLE.h>
#include <Wire.h>
#include "SHTSensor.h"
SHTSensor sht;
const int buttonPin = 2; // set buttonPin to digital pin
const float REFERENCE_VOLTS = 3.3f; // +3.3V regulated supply voltage
const float R1 = 330000.0f; // Resistor values of voltage divider
const float R2 = 1200000.0f;
const float RESISTOR_FACTOR = 4095.0f * (R2 / (R1 + R2)); // Using 12-bit resolution: multiply by 4095
// create service:
BLEService SHT4XService("0x44");
// create characteristics and allow remote device to read and get notifications:
BLEIntCharacteristic Temperature("0x44", BLERead | BLENotify);
BLEIntCharacteristic Humidity("0x44", BLERead | BLENotify);
// create button characteristic and allow remote device to get notifications
BLEByteCharacteristic buttonCharacteristic("19B10012-E8F2-537E-4F6C-D104768A1214", BLERead | BLENotify);
BLEUnsignedCharCharacteristic batteryLevelChar("2A19", // standard 16-bit characteristic UUID
BLERead | BLENotify); // remote clients will be able to get notifications if this characteristic changes
//SETUP_______________________________________________________________________________________________
void setup() {
Serial.begin(9600);
Wire.begin();
pinMode(buttonPin, INPUT); // use button pin as an input
int batteryLevel = analogRead(ADC_BATTERY); // Read the battery level from the ADC
if (sht.init()) {
Serial.print("init(): success\n");
} else {
Serial.print("init(): failed\n");
}
pinMode(LED_BUILTIN, OUTPUT);// Visual indication on the MKR Wifi 1010 that the central device is connected
// begin initialization
while (!BLE.begin()) {
Serial.println("Waiting for BLE to start");
delay(1);
}
// set the local name that the peripheral advertises:
BLE.setLocalName("SHT4XSensor");
// set the UUID for the service:
BLE.setAdvertisedService(SHT4XService);
// add the characteristics to the service
SHT4XService.addCharacteristic(Temperature);
SHT4XService.addCharacteristic(Humidity);
SHT4XService.addCharacteristic(buttonCharacteristic);
SHT4XService.addCharacteristic(batteryLevelChar); // add the battery level characteristic
batteryLevelChar.writeValue(batteryLevel); // set initial value for this characteristic
// add the service
BLE.addService(SHT4XService);
// Get state of tamper detection
buttonCharacteristic.writeValue(0);
// start advertising the service:
BLE.advertise();
analogReadResolution(12); // Set the analog resolution to 12-bits
}
//LOOP_______________________________________________________________________________________________
void loop() {
// poll for Bluetooth® Low Energy events
BLE.poll();
// read the current button pin state
char buttonValue = digitalRead(buttonPin);
// has the value changed since the last read
bool buttonChanged = (buttonCharacteristic.value() != buttonValue);
if (buttonChanged) {
// button state changed, update characteristics
buttonCharacteristic.writeValue(buttonValue);
}
//Print temp and humidity values to serial monitor
if (sht.readSample()) {
Serial.print("SHT:\n");
Serial.print(" RH: ");
Serial.print(sht.getHumidity(), 2),
Serial.print("\n");
Serial.print(" T: ");
Serial.print(sht.getTemperature(), 2);
Serial.print("\n");
Serial.print(" Open?: ");
Serial.print(digitalRead(buttonPin));
Serial.print("\n");
int batteryLevel = analogRead(ADC_BATTERY); // Read the battery level from the ADC
float volts = (batteryLevel / RESISTOR_FACTOR) * REFERENCE_VOLTS; // Calculate the battery voltage
Serial.print(F("Battery Level: ")); // Display the results
Serial.print(volts);
Serial.println(F("V"));
} else {
Serial.print("Error in readSample()\n");
}
delay(1000);
BLEDevice central = BLE.central();
// if a central is connected to the peripheral:
if (central) {
// print the central's BT address:
Serial.print("Connected to central: ");
Serial.println(central.address());
// turn on LED to indicate connection:
digitalWrite(LED_BUILTIN, HIGH);
// while the central remains connected:
while (central.connected()) {
// read sensors:
// write sensor values to service characteristics:
Temperature.writeValue(sht.getTemperature());
Humidity.writeValue(sht.getHumidity());
if (buttonChanged) {
// button state changed, update characteristics
buttonCharacteristic.writeValue(buttonValue);
}
int batteryLevel = analogRead(ADC_BATTERY); // Read the battery level from the ADC
batteryLevelChar.writeValue(batteryLevel); // and update the battery level characteristic
// turn off the LED
digitalWrite(LED_BUILTIN, LOW);
}
}
}
BTW, thanks for the reply
JIm
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.