Last active
July 15, 2017 07:02
-
-
Save ma2shita/17b2631909090c455db7166f9a963e4f to your computer and use it in GitHub Desktop.
1-wire temperture "DS18B20" + LoRaWAN Shield
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* ** 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