Writing Code to Artificial Intelligence

Writing Code to Artificial Intelligence

As one of the site editors, I wanted to participate in Artificial Intelligence, the most popular and rapidly developing field of the last few years.

I examined the Artificial Intelligence applications of different companies. I tested the Copy.ai artificial intelligence application, one of the first popular ones, by asking different questions.

Then I experimented with different topics on chat.openai.com.

I examined Microsoft's artificial intelligence application only in terms of visual applications.

In fact, as it is known, Google had started artificial intelligence applications years ago, but did not make a breakthrough for users to use it openly.

After this short introduction about artificial intelligence, let's come to our main question. Writing code to Artificial Intelligence?

We are making Android applications with some microcontrollers on our site. We use Flutter-Dart codes to make Android apps. We also do coding examples on the microcontroller side.

When we ask the chat.openai artificial intelligence about some examples we have published on our site, it gives very good answers. Flutter-Dart is pretty good at coding and Arduino coding.

I asked openAi artificial intelligence to write a code about a relatively new topic, "Can you write sample codes for Arduino and MQTT Publisher?" I asked one. Response time did not reach 10 seconds. Before writing the sample codes, let me give a short excerpt about MQTT:

MQTT (Message Queuing Telemetry Transport) is a messaging protocol. It is designed for use between devices that require low bandwidth and low power consumption, and is often used for data transmission between Internet of Things (IoT) devices.

MQTT uses the broadcast-subscription model and provides a way for devices to broadcast data and for other devices to receive it. Messages are managed by a server called an MQTT Broker and subscribers subscribe to a specific thread to receive messages.

The MQTT system consists of the following components:

Publisher: A device that sends a message to a specific topic.
Subscriber: A device that subscribes to a specific topic and receives messages from that topic.

Broker: It is the medium where Publishers and Subscribers communicate. It is responsible for forwarding incoming messages to the correct subscribers.

Topic: Specifies the topics of the messages. It determines which topics the subscriber will subscribe to.

QoS (Quality of Service): Specifies the transmission quality of messages. There are 3 different QoS levels in MQTT.

Retained messages: These are the messages that keep the last values. Subscribers can use retained messages to get the latest values.

Publisher, one of the MQTT components, is the component that sends data under a certain topic. Data can be any kind of data; temperature, light intensity, decibel etc.

How to do our example question with a microcontroller system? We asked how. Of course, the same question can be asked for any other microcontroller board.

After the question we asked, the codes that openai gave are below:

#include <PubSubClient.h>
#include <WiFi.h>

const char* ssid = "SSID";
const char* password = "PASSWORD";
const char* mqtt_server = "BROKER IP";
const char* topic = "test";

WiFiClient espClient;
PubSubClient client(espClient);

void setup() {
   Serial.begin(9600);
   WiFi.begin(ssid, password);

   while (WiFi.status() != WL_CONNECTED) {
     delay(1000);
     Serial.println("Connecting to WiFi...");
   }
   Serial.println("Connected to WiFi");
   client.setServer(mqtt_server, 1883);
   while (!client.connected()) {
     Serial.println("Connecting to MQTT server...");
     if (client.connect("arduino-client")) {
       Serial.println("Connected to MQTT server");
     } else {
       Serial.print("Failed with state ");
       Serial.print(client.state());
       delay(2000);
     }
   }
}
void loop() {
   client.loop();
   client.publish(topic, "hello world");
   delay(5000);
}

Of course, it's nice that artificial intelligence helps us with coding. However, there is an important issue: do we have enough information to ask questions?

What do we need to know for these codes to really help us? Let's look at the codes above again...

How well do we know, for example, a TCP/IP issue, although it is never mentioned as a term in the code?

These codes can be very useful when making beginner and intermediate applications. However, we need to have knowledge of many technical issues when making advanced IoT applications.

 

About Ümit Sönmez: Electronic-Computer Trainer, Author