Skip to content

Instantly share code, notes, and snippets.

@ma2shita
Last active July 15, 2017 07:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ma2shita/17b2631909090c455db7166f9a963e4f to your computer and use it in GitHub Desktop.
Save ma2shita/17b2631909090c455db7166f9a963e4f to your computer and use it in GitHub Desktop.
1-wire temperture "DS18B20" + LoRaWAN Shield
/* ** Hardware setup **
* Arduino UNO R3 + LoRaWAN Shield + DS18B20
*
* VCC(red) ------+---- 5V
* |
* DS18B20 10K Arduino
* |
* BUS(yellow) ---+---- 6
* GND(black) --------- GND
*/
/* ** Software setup **
* OneWire: https://github.com/adafruit/MAX31850_OneWire
* DallasTemperature : https://github.com/adafruit/MAX31850_DallasTemp
*/
#define ONE_WIRE_BUS 6 // 1-wire bus(data) port
#define INTERVAL 4800 /* msec */
#include <OneWire.h>
#include <DallasTemperature.h>
#include <lorawan_client.h>
LoRaWANClient lorawanClient;
OneWire oneWire(ONE_WIRE_BUS);
#define SENSER_BIT 11 // precision
DallasTemperature temper(&oneWire);
boolean usingLoRaWAN = false;
void setup(void) {
Serial.begin(9600);
temper.setResolution(SENSER_BIT);
pinMode(13, OUTPUT);
if (usingLoRaWAN) {
if (!lorawanClient.connect()) {
Serial.println(" failed to connect. Halt...");
for(;;){};
}
}
}
void loop(void) {
temper.requestTemperatures();
float t = temper.getTempCByIndex(0);
char buf[10];
dtostrf(t, 4, 1, buf);
char json[16];
sprintf(json, "{\"t\":%s}", buf);
Serial.println(json);
if (usingLoRaWAN) {
lorawanClient.sendData(json);
digitalWrite(13, LOW);
for (int i = 0 ; i < 2 ; i++) {
digitalWrite(13, HIGH);
delay(100);
digitalWrite(13, LOW);
delay(100);
}
digitalWrite(13, LOW);
}
delay(INTERVAL);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment