Android vs Raspberry Pi Chat
Simplest chat ever seen, and with a chance to change messages by commands in a bidirectional fashion.
Components and supplies
1
Raspberry Pi 3 Model B
Apps and platforms
1
Abetoo IoT Framework
Project description
Code
Raspberry Pi code
csharp
1using Abetoo; 2using System; 3using System.Collections.Generic; 4using System.ComponentModel; 5using System.Data; 6using System.Drawing; 7using System.Linq; 8using System.Text; 9using System.Threading.Tasks; 10using System.Windows.Forms; 11 12namespace pcChatApp 13{ 14 public partial class form1 : Form 15 { 16 AbtooConnection abconnection; 17 18 public form1() 19 { 20 InitializeComponent(); 21 22 // Connection parameters 23 const String myChannel = 24 "-TbVO-rqdA0iWg6-gWh0eeQ636243460528994051#" + 25 "735acf9cd6eda96e66ee3858496dca59d750aff1"; 26 27 const int heartBeat = 4; 28 29 // Connection 30 abconnection = new AbtooConnection(myChannel, heartBeat); 31 32 // Messages Listener 33 abconnection.messageReceived += ((sender, abtoomsg) => 34 { 35 AbtooMessage abmsg = (AbtooMessage)abtoomsg; 36 37 this.Invoke((MethodInvoker)(() => 38 { 39 listBox1.Items.Add("Remote: " + abmsg.body); 40 listBox1.SelectedIndex = listBox1.Items.Count - 1; 41 listBox1.SelectedIndex = -1; 42 listBox1.Refresh(); 43 })); 44 //Console.WriteLine(abmsg.body); 45 }); 46 abconnection.connect(); 47 48 } 49 50 private void button1_Click(object sender, EventArgs e) 51 { 52 const String remoteChannel = 53 "-uC6s1LfZaEuw9AK0Js1w9w636243459698606497#" + 54 "b90a9186b9b61ead17d51251f689aea1779d5203"; 55 56 57 abconnection.sendMessage(remoteChannel, messageBox.Text); 58 listBox1.Items.Add("Me: " + messageBox.Text); 59 listBox1.SelectedIndex = listBox1.Items.Count - 1; 60 listBox1.SelectedIndex = -1; 61 listBox1.Refresh(); 62 messageBox.Text = ""; 63 64 } 65 66 private void messageBox_KeyDown(object sender, KeyEventArgs e) 67 { 68 if (e.KeyCode == Keys.Enter) 69 { 70 button1_Click(sender, null); 71 e.Handled = true; 72 e.SuppressKeyPress = true; 73 } 74 } 75 } 76}
Comments
Only logged in users can leave comments