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.
Fork of MilkcocoaOsSample_Eth by
main.cpp@8:7d2252cf70e1, 2018-02-15 (annotated)
- Committer:
- jksoft
- Date:
- Thu Feb 15 20:51:54 2018 +0000
- Revision:
- 8:7d2252cf70e1
- Parent:
- 5:103da32c92c7
- Child:
- 9:9bcdb7b2cd1b
???????Milkcocoa?push??
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| jksoft | 0:885b53a42035 | 1 | #include "mbed.h" |
| jksoft | 0:885b53a42035 | 2 | #include "Milkcocoa.h" |
| jksoft | 0:885b53a42035 | 3 | #include "EthernetInterface.h" |
| jksoft | 0:885b53a42035 | 4 | |
| jksoft | 0:885b53a42035 | 5 | EthernetInterface eth; |
| jksoft | 0:885b53a42035 | 6 | RawSerial pc(USBTX,USBRX); |
| jksoft | 8:7d2252cf70e1 | 7 | DigitalIn input(D7); |
| jksoft | 8:7d2252cf70e1 | 8 | //AnalogIn input(A0); |
| jksoft | 0:885b53a42035 | 9 | |
| jksoft | 0:885b53a42035 | 10 | /************************* Your Milkcocoa Setup *********************************/ |
| jksoft | 0:885b53a42035 | 11 | |
| jksoft | 8:7d2252cf70e1 | 12 | #define MILKCOCOA_APP_ID "postite082h1" |
| jksoft | 0:885b53a42035 | 13 | #define MILKCOCOA_DATASTORE "mbed_lan" |
| jksoft | 0:885b53a42035 | 14 | |
| jksoft | 0:885b53a42035 | 15 | /************* Milkcocoa Setup (you don't need to change this!) ******************/ |
| jksoft | 0:885b53a42035 | 16 | |
| jksoft | 0:885b53a42035 | 17 | #define MILKCOCOA_SERVERPORT 1883 |
| jksoft | 0:885b53a42035 | 18 | |
| jksoft | 0:885b53a42035 | 19 | /************ Global State (you don't need to change this!) ******************/ |
| jksoft | 0:885b53a42035 | 20 | const char MQTT_SERVER[] = MILKCOCOA_APP_ID ".mlkcca.com"; |
| jksoft | 0:885b53a42035 | 21 | const char MQTT_CLIENTID[] = __TIME__ MILKCOCOA_APP_ID; |
| jksoft | 0:885b53a42035 | 22 | |
| jksoft | 8:7d2252cf70e1 | 23 | //extern void onpush(MQTT::MessageData& md); |
| jksoft | 0:885b53a42035 | 24 | |
| jksoft | 0:885b53a42035 | 25 | int main() { |
| jksoft | 0:885b53a42035 | 26 | |
| jksoft | 0:885b53a42035 | 27 | pc.baud(9600); |
| jksoft | 0:885b53a42035 | 28 | pc.printf("Milkcocoa mbed os ver demo\n\r\n\r\n\r"); |
| jksoft | 0:885b53a42035 | 29 | |
| jksoft | 0:885b53a42035 | 30 | int ret = eth.connect(); |
| jksoft | 0:885b53a42035 | 31 | if (ret != 0) { |
| jksoft | 0:885b53a42035 | 32 | printf("\r\nConnection error\r\n"); |
| jksoft | 0:885b53a42035 | 33 | return -1; |
| jksoft | 0:885b53a42035 | 34 | } |
| jksoft | 0:885b53a42035 | 35 | pc.printf("\n\rEthernet connected\n\r"); |
| jksoft | 0:885b53a42035 | 36 | |
| jksoft | 0:885b53a42035 | 37 | Milkcocoa* milkcocoa = new Milkcocoa(ð, MQTT_SERVER, MILKCOCOA_SERVERPORT, MILKCOCOA_APP_ID, MQTT_CLIENTID); |
| jksoft | 0:885b53a42035 | 38 | |
| jksoft | 0:885b53a42035 | 39 | milkcocoa->connect(); |
| jksoft | 0:885b53a42035 | 40 | |
| jksoft | 8:7d2252cf70e1 | 41 | //pc.printf("%d\n\r",milkcocoa->on(MILKCOCOA_DATASTORE, "push", onpush)); |
| jksoft | 0:885b53a42035 | 42 | |
| jksoft | 0:885b53a42035 | 43 | while(1) { |
| jksoft | 0:885b53a42035 | 44 | DataElement elem = DataElement(); |
| jksoft | 8:7d2252cf70e1 | 45 | elem.setValue("input", input); |
| jksoft | 0:885b53a42035 | 46 | |
| jksoft | 0:885b53a42035 | 47 | milkcocoa->push(MILKCOCOA_DATASTORE, elem); |
| jksoft | 0:885b53a42035 | 48 | |
| jksoft | 5:103da32c92c7 | 49 | milkcocoa->loop(); |
| jksoft | 0:885b53a42035 | 50 | Thread::wait(7000); |
| jksoft | 0:885b53a42035 | 51 | |
| jksoft | 0:885b53a42035 | 52 | } |
| jksoft | 0:885b53a42035 | 53 | } |
| jksoft | 0:885b53a42035 | 54 | |
| jksoft | 8:7d2252cf70e1 | 55 | #if 0 |
| jksoft | 0:885b53a42035 | 56 | void onpush(MQTT::MessageData& md) |
| jksoft | 0:885b53a42035 | 57 | { |
| jksoft | 0:885b53a42035 | 58 | MQTT::Message &message = md.message; |
| jksoft | 0:885b53a42035 | 59 | DataElement de = DataElement((char*)message.payload); |
| jksoft | 0:885b53a42035 | 60 | pc.printf("onpush\n\r"); |
| jksoft | 0:885b53a42035 | 61 | pc.printf("%d\n\r",de.getInt("v")); |
| jksoft | 8:7d2252cf70e1 | 62 | } |
| jksoft | 8:7d2252cf70e1 | 63 | #endif |
