Skip to content

Instantly share code, notes, and snippets.

/mongo rust Secret

Created August 28, 2017 06:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/d455b8386dd5d4832784483d4950beb0 to your computer and use it in GitHub Desktop.
Save anonymous/d455b8386dd5d4832784483d4950beb0 to your computer and use it in GitHub Desktop.
extern crate sysfs_gpio;
extern crate bson;
extern crate mongodb;
#[macro_use(bson,doc)]
use sysfs_gpio::{Direction, Pin};
use std::thread::sleep;
use std::time::Duration;
use bson::Bson;
use mongodb::{Client, ThreadedClient};
use mongodb::db::ThreadedDatabase;
fn main() {
let client = Client::connect("ipaddress", 27017)
.expect("Failed to initialize standalone client.");
let coll = client.db("DEVICES").collection("01");
let doc = doc! { "title" => "Jaws","array" => [ 1, 2, 3 ] };
let temp_up = Pin::new(2);
let temp_down = Pin::new(3);
let mypin = Pin::new(14);
let mypin2 = Pin::new(16);
temp_down.with_exported(|| {
temp_up.set_direction(Direction::In).unwrap();
temp_down.set_direction(Direction::In).unwrap();
mypin2.set_direction(Direction::Out).unwrap();
mypin.set_direction(Direction::Out).unwrap();
loop {
let hotter = temp_up.get_value()?;
let cooler = temp_down.get_value()?;
if hotter == 0 {
mypin.set_value(1).unwrap();
println!("{:?}", "making hotter");
sleep(Duration::from_millis(500));
mypin.set_value(0).unwrap();
coll.insert_one(doc.clone(), None)
.ok().expect("Failed to insert document.");
} else if cooler == 0 {
mypin2.set_value(1).unwrap();
println!("{:?}", "making cooler");
sleep(Duration::from_millis(500));
mypin2.set_value(0).unwrap();
coll.insert_one(doc.clone(), None)
.ok().expect("Failed to insert document.");
}
}
}).unwrap();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment