Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: Adafruit_GFX 19E042PIM_MB_PINS
Revision 1:23fbbef17db0, committed 2021-12-11
- Comitter:
- lule
- Date:
- Sat Dec 11 16:27:59 2021 +0000
- Parent:
- 0:3ce69fe83309
- Commit message:
- Aleksandar Lukic;
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Sat Dec 11 15:52:37 2021 +0000
+++ b/main.cpp Sat Dec 11 16:27:59 2021 +0000
@@ -36,10 +36,11 @@
Adafruit_SSD1306_I2c myOLED(i2c_obj, PB_5, I2C_ADD_MBED, OLED_HEIGHT_PX, OLED_WIDTH_PX);
char* topic_sub = "subpim";
-char* topic_pub = "pubpim26";
+char* topic_pub = "pubpim";
const char* hostname = "broker.hivemq.com";
int port = 1883;
int button_pressed = 0;
+int send_data = 0;
/* function definition */
void messageArrived(MQTT::MessageData& md)
@@ -47,11 +48,16 @@
MQTT::Message &message = md.message;
//printf("Browser message: %.*s \n", message.payloadlen, (char*)message.payload);
- myOLED.begin();
myOLED.clearDisplay();
myOLED.setTextCursor(0, 0);
myOLED.printf("%.*s", message.payloadlen, (char*)message.payload);
myOLED.display();
+
+ /*if(((char*)message.payload[0] == 's') && ((char*)message.payload[1] == 't') &&
+ ((char*)message.payload[2] == 'a') && ((char*)message.payload[3] == 'r') &&
+ ((char*)message.payload[4] == 't')){
+ send_data = 1;
+ }*/
}
void ISR_sw1()
@@ -63,6 +69,7 @@
int main()
{
+ myOLED.begin();
sw1.fall(&ISR_sw1); // sw1 interrupt
wifi = WiFiInterface::get_default_instance(); //init wifi
@@ -73,9 +80,9 @@
//myOLED.display();
return -1;
}
- //myOLED.printf("Success\n");
- //myOLED.display();
- //wait(2);
+ myOLED.printf("Success\n");
+ myOLED.display();
+ wait(2);
socket.open(wifi);
socket.connect(hostname,port);
@@ -89,8 +96,8 @@
i2c_obj.frequency(I2C_FREQUENCY);
- //myOLED.clearDisplay();
- //myOLED.display();
+ myOLED.clearDisplay();
+ myOLED.display();
while(1) {
@@ -100,6 +107,12 @@
button_pressed = 0;
char buf[100];
sprintf(buf, "V(POT1) = %1.2f \r\n", pot1*(3.3f));
+
+ myOLED.clearDisplay();
+ myOLED.setTextCursor(0, 0);
+ //myOLED.printf("%.*s", buf.payloadlen, (char*)buf.payload);
+ myOLED.display();
+
message.qos = MQTT::QOS0;
message.retained = false;
message.dup = false;