Update init.js

Adjusted status light and removed lightPin RPC reading. lightPin not supported on v1 hardware.
This commit is contained in:
Latitude17 2018-03-15 16:51:02 -06:00 committed by GitHub
parent aac43fb743
commit f919b5ea12
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 26 additions and 15 deletions

View File

@ -24,16 +24,11 @@ GPIO.write(statusLightPin, 0);
GPIO.set_mode(resetPin, GPIO.MODE_INPUT); GPIO.set_mode(resetPin, GPIO.MODE_INPUT);
GPIO.set_int_handler(resetPin, GPIO.INT_EDGE_NEG, function(resetPin) { GPIO.set_int_handler(resetPin, GPIO.INT_EDGE_NEG, function(resetPin) {
print('Pin', resetPin, 'got interrupt'); print('Pin', resetPin, 'got interrupt');
for (let i=0; i<=5; i++)
{
GPIO.toggle(statusLightPin); GPIO.toggle(statusLightPin);
Sys.usleep(200000); Sys.usleep(200000);
GPIO.toggle(statusLightPin); }
Sys.usleep(200000);
GPIO.toggle(statusLightPin);
Sys.usleep(200000);
GPIO.toggle(statusLightPin);
Sys.usleep(200000);
GPIO.toggle(statusLightPin);
Sys.usleep(200000);
GPIO.write(statusLightPin, 0); GPIO.write(statusLightPin, 0);
Cfg.set({bt:{enable:true}}); Cfg.set({bt:{enable:true}});
@ -43,12 +38,20 @@ GPIO.set_int_handler(resetPin, GPIO.INT_EDGE_NEG, function(resetPin) {
Sys.reboot(1000); Sys.reboot(1000);
}, null); }, null);
GPIO.enable_int(resetPin);
print("Starting...");
GPIO.enable_int(resetPin);
ADC.enable(moisturePin); ADC.enable(moisturePin);
let dht = DHT.create(dhtPin, DHT.DHT11); let dht = DHT.create(dhtPin, DHT.DHT11);
let deviceId = Cfg.get("device.id"); let deviceId = Cfg.get("device.id");
if (deviceId === "")
{
deviceId = Cfg.get("higrow.deviceId");
Cfg.set("device.id", deviceId);
}
let connected = false; let connected = false;
let readSensors = Timer.set(5000, Timer.REPEAT, function() { let readSensors = Timer.set(5000, Timer.REPEAT, function() {
let t = dht.getTemp(); let t = dht.getTemp();
@ -59,7 +62,8 @@ let readSensors = Timer.set(5000, Timer.REPEAT, function() {
if (deviceId !== "" && connected) if (deviceId !== "" && connected)
{ {
GPIO.write(statusLightPin, 1); GPIO.write(statusLightPin, 0);
let jsonData = {'DeviceId': deviceId, 'Temperature': t, 'Humidity': h, 'Moisture': m}; let jsonData = {'DeviceId': deviceId, 'Temperature': t, 'Humidity': h, 'Moisture': m};
HTTP.query({ HTTP.query({
headers: {'Content-Type' : 'application/json'}, headers: {'Content-Type' : 'application/json'},
@ -78,8 +82,13 @@ let readSensors = Timer.set(5000, Timer.REPEAT, function() {
}, },
}); });
GPIO.write(statusLightPin, 1);
//Timer.del(readSensors); //Timer.del(readSensors);
} }
else
{
print("DeviceId:",deviceId,"Connected:",connected);
}
}, null); }, null);
@ -90,12 +99,12 @@ RPC.addHandler('HG.Temp.Read', function(args){
RPC.addHandler('HG.Humidity.Read', function(args){ RPC.addHandler('HG.Humidity.Read', function(args){
return { value: dht.getHumidity() }; return { value: dht.getHumidity() };
}); });
RPC.addHandler('HG.Light.Read', function(args){
return { value: ADC.read(lightPin) };
});
RPC.addHandler('HG.Moisture.Read', function(args){ RPC.addHandler('HG.Moisture.Read', function(args){
return { value: ADC.read(moisturePin) }; return { value: ADC.read(moisturePin) };
}); });
RPC.addHandler('HG.StatusLED.Read', function(args){
return { value: GPIO.read(statusLightPin) };
});
RPC.addHandler('HG.StatusLED.On', function(args){ RPC.addHandler('HG.StatusLED.On', function(args){
GPIO.write(statusLightPin, 0); GPIO.write(statusLightPin, 0);
print("LED On"); print("LED On");
@ -134,4 +143,6 @@ Event.addGroupHandler(Net.EVENT_GRP, function(ev, evdata, arg) {
evs = 'GOT_IP'; evs = 'GOT_IP';
connected = true; connected = true;
} }
print(evs);
}, null); }, null);