Jovana Trajkovic
/
19E042PIM_TJAN_2019_0408
2019/0408
Diff: main.cpp
- Revision:
- 0:21b40f6bfff0
diff -r 000000000000 -r 21b40f6bfff0 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Mon Jan 17 16:01:28 2022 +0000 @@ -0,0 +1,71 @@ + +// Uvoz biblioteka +#include "mbed-os" +#include "platform/mbed_thread.h" +#include "MQTTClientMbedOs.h" + +// Definisanje direktiva + +#define VOLTAGE_SCALER 3.3f +#define YIELD_TIMEOUT_MS 1000 +#define MAX_HEIGHT 64 +#define MAX_WIDTH 128 + +// Deklaracija glavnih promenljivih + +TCPSOcket socket; +MQTTClient client(&socket); +MQTT::Message message; + +WiFiInterface *wifi; +WiFiAccessPoint *ap = new WiFiAccessPoint[count]; + +Adafruit_SSD1306_I2c myOled(i2c, rst, i2c_adress, height, width); +I2C i2c(PB_14, PB_13); +// Pisanje sporednih funkcija + + + +// Pisanje glavne funkcije + +int main() +{ + while(1) + { + + wifi = WiFiInterface:;get_default_instance(); + + int count = wifi->scan(NULL, 0); + count wifi->scan(ap,count); + + wifi->connect(MBED_CONF_APP_SSID, MBED_CONF_APP_WIFI_PASSWORD, + NSAPI_SECURITY_WPA_WPA2); + + socket.open(wifi); + socket.connect(hostname, port); + + MQTTPacket_connectData = MQTT_Packet_connectData_initializer; + data.MQTTVersion = 3; + data.clientID.cstring = "custom_client_ID"; + client.connect((data)); + + client.subscribe(topic_sub, MQTT::QOS2, messageArrived)); + + char buf[100]; + sprintf(buf, "V(POT1) = %1.2f\r\n", pot1*VOLTAGE_SCALER); + + message.qos = MQTT::QOS0; + message.retained = false; + message.dup + false; + message.payload = (void*)buf; + message.payloadlen = strlen(buf)+1; + client.publish(topic, message); + + client.yield(YIELD_TIMEOUT_MS); + + + +} + + +} \ No newline at end of file