Skip to content

Instantly share code, notes, and snippets.

@thutch
Created June 24, 2014 03:22
Show Gist options
  • Save thutch/028e34d6760f4ad57c14 to your computer and use it in GitHub Desktop.
Save thutch/028e34d6760f4ad57c14 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using RabbitMQ.Client;
using RaspberryPi.GPIO;
namespace ButtonPress
{
class Program
{
static void Main(string[] args)
{
using (var gpio = new GPIOMem(GPIOPins.V2_GPIO_23, GPIODirection.In))
{
var factory = new ConnectionFactory() {HostName = "10.0.0.15"};
System.Console.WriteLine("Connecting to RabbitMq server");
var connection = factory.CreateConnection();
var channel = connection.CreateModel();
channel.ExchangeDeclare("buttonPress", "fanout");
Console.WriteLine("Waiting on button press");
var reading = false;
while (true)
{
reading = gpio.Read();
if (!reading)
{
Console.WriteLine("Button Pressed");
var message = string.Format("ButtonPressed");
var body = Encoding.UTF8.GetBytes(message);
channel.BasicPublish("buttonPress", "", null, body);
Console.WriteLine("Sent message '{0}' to Queue", message);
}
Thread.Sleep(100);
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment