Hackster is hosting Impact Spotlights: Industrial Automation. Watch the stream live on Thursday!Hackster is hosting Impact Spotlights: Industrial Automation. Stream on Thursday!
abetoo
Published © GPL3+

Android vs Raspberry Pi Chat

Simplest chat ever seen, and with a chance to change messages by commands in a bidirectional fashion.

BeginnerProtip2,092
Android vs Raspberry Pi Chat

Things used in this project

Hardware components

Raspberry Pi 3 Model B
Raspberry Pi 3 Model B
×1

Software apps and online services

Abetoo IoT Framework

Story

Read more

Code

Raspberry Pi code

C#
using Abetoo;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace pcChatApp
{
    public partial class form1 : Form
    {
        AbtooConnection abconnection;

        public form1()
        {
            InitializeComponent();

            // Connection parameters
            const String myChannel =
                "-TbVO-rqdA0iWg6-gWh0eeQ636243460528994051#" +
                "735acf9cd6eda96e66ee3858496dca59d750aff1";

            const int heartBeat = 4;

            // Connection
            abconnection = new AbtooConnection(myChannel, heartBeat);

            // Messages Listener
            abconnection.messageReceived += ((sender, abtoomsg) =>
            {
                AbtooMessage abmsg = (AbtooMessage)abtoomsg;

                this.Invoke((MethodInvoker)(() =>
                    {
                        listBox1.Items.Add("Remote: " + abmsg.body);
                        listBox1.SelectedIndex = listBox1.Items.Count - 1;
                        listBox1.SelectedIndex = -1;
                        listBox1.Refresh();
                    }));
                //Console.WriteLine(abmsg.body);
            });
            abconnection.connect();

        }

        private void button1_Click(object sender, EventArgs e)
        {
            const String remoteChannel =
            "-uC6s1LfZaEuw9AK0Js1w9w636243459698606497#" +
            "b90a9186b9b61ead17d51251f689aea1779d5203";
                

            abconnection.sendMessage(remoteChannel, messageBox.Text);
            listBox1.Items.Add("Me: " + messageBox.Text);
            listBox1.SelectedIndex = listBox1.Items.Count - 1;
            listBox1.SelectedIndex = -1;
            listBox1.Refresh();
            messageBox.Text = "";

        }

        private void messageBox_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                button1_Click(sender, null);
                e.Handled = true;
                e.SuppressKeyPress = true;
            }
        }
     }
}

Credits

abetoo
0 projects • 7 followers
Software and Hardware Development
Contact

Comments

Please log in or sign up to comment.